コード例 #1
0
        private async Task <int> GetNewReportInstancesCountAsync(Guid workFlowGuid)
        {
            var compareDate = await PrepareComparisonForNewReportDateAsync();

            var predicate = PredicateBuilder.New <ReportInstance>(true);

            predicate = predicate.And(f => f.WorkFlow.WorkFlowGuid == workFlowGuid);
            predicate = predicate.And(f => f.Created >= compareDate);

            var reportInstancesFromRepo = await _reportInstanceRepository.ListAsync(predicate, null, new string[] { "" });

            return(reportInstancesFromRepo.Count);
        }
コード例 #2
0
        public async Task <LinkedCollectionResourceWrapperDto <FacilityTypeIdentifierDto> > Handle(FacilityTypesIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <FacilityType>(message.OrderBy, "asc");

            var pagedFacilityTypesFromRepo = await _facilityTypeRepository.ListAsync(pagingInfo, null, orderby, "");

            if (pagedFacilityTypesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedFacilityTypes = PagedCollection <FacilityTypeIdentifierDto> .Create(_mapper.Map <PagedCollection <FacilityTypeIdentifierDto> >(pagedFacilityTypesFromRepo),
                                                                                              pagingInfo.PageNumber,
                                                                                              pagingInfo.PageSize,
                                                                                              pagedFacilityTypesFromRepo.TotalCount);

                var wrapper = new LinkedCollectionResourceWrapperDto <FacilityTypeIdentifierDto>(pagedFacilityTypesFromRepo.TotalCount, mappedFacilityTypes, pagedFacilityTypesFromRepo.TotalPages);

                return(wrapper);
            }

            return(null);
        }
コード例 #3
0
        private async Task MapCaseNumberAsync(PatientDetailDto mappedPatient)
        {
            int[] terms = _patientConditionRepository.List(pc => pc.Patient.Id == mappedPatient.Id && pc.TerminologyMedDra != null && !pc.Archived && !pc.Patient.Archived, null, new string[] { "Condition", "TerminologyMedDra" })
                          .Select(p => p.TerminologyMedDra.Id)
                          .ToArray();
            var conditionMeddras = await _conditionMeddraRepository.ListAsync(cm => terms.Contains(cm.TerminologyMedDra.Id), null, new string[] { "Condition", "TerminologyMedDra" });

            var patientFromRepo = await _patientRepository.GetAsync(p => p.Archived == false &&
                                                                    p.Id == mappedPatient.Id,
                                                                    new string[] { "PatientConditions.TerminologyMedDra", "PatientConditions.Outcome", "PatientConditions.TreatmentOutcome" });

            List <PatientConditionGroupDto> groupArray = new List <PatientConditionGroupDto>();

            foreach (var conditionMeddra in conditionMeddras)
            {
                var currentConditionGroup = conditionMeddra.GetConditionForPatient(patientFromRepo);
                if (currentConditionGroup != null)
                {
                    if (!String.IsNullOrWhiteSpace(currentConditionGroup.CaseNumber))
                    {
                        mappedPatient.CaseNumber.Add(currentConditionGroup.CaseNumber);
                    }
                }
            }
        }
コード例 #4
0
        private async Task CustomConditionMapAsync(Patient patientFromRepo, PatientExpandedDto mappedPatient)
        {
            int[] terms = _patientConditionRepository.List(pc => pc.Patient.Id == mappedPatient.Id && pc.TerminologyMedDra != null && !pc.Archived && !pc.Patient.Archived, null, new string[] { "Condition" })
                          .Select(p => p.TerminologyMedDra.Id)
                          .ToArray();
            var conditionMeddras = await _conditionMeddraRepository.ListAsync(cm => terms.Contains(cm.TerminologyMedDra.Id), null, new string[] { "Condition", "TerminologyMedDra" });

            List <PatientConditionGroupDto> groupArray = new List <PatientConditionGroupDto>();

            foreach (var conditionMeddra in conditionMeddras)
            {
                var tempCondition = conditionMeddra.GetConditionForPatient(patientFromRepo);
                if (tempCondition != null)
                {
                    var group = new PatientConditionGroupDto()
                    {
                        ConditionGroup     = conditionMeddra.Condition.Description,
                        Status             = tempCondition.OutcomeDate != null ? "Case Closed" : "Case Open",
                        PatientConditionId = tempCondition.Id,
                        StartDate          = tempCondition.OnsetDate.ToString("yyyy-MM-dd"),
                        Detail             = String.Format("{0} started on {1}", tempCondition.TerminologyMedDra.DisplayName, tempCondition.OnsetDate.ToString("yyyy-MM-dd"))
                    };
                    groupArray.Add(group);
                }
            }
            mappedPatient.ConditionGroups = groupArray;
        }
コード例 #5
0
        public async Task <LinkedCollectionResourceWrapperDto <FacilityIdentifierDto> > Handle(FacilitiesIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <Facility>(message.OrderBy, "asc");

            var pagedFacilitiesFromRepo = await _facilityRepository.ListAsync(pagingInfo, null, orderby, "");

            if (pagedFacilitiesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedFacilities = PagedCollection <FacilityIdentifierDto> .Create(_mapper.Map <PagedCollection <FacilityIdentifierDto> >(pagedFacilitiesFromRepo),
                                                                                       pagingInfo.PageNumber,
                                                                                       pagingInfo.PageSize,
                                                                                       pagedFacilitiesFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedFacilities.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <FacilityIdentifierDto>(pagedFacilitiesFromRepo.TotalCount, mappedFacilities, pagedFacilitiesFromRepo.TotalPages);

                CreateLinksForFacilities(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                         pagedFacilitiesFromRepo.HasNext, pagedFacilitiesFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #6
0
        public async Task <bool> Handle(DeleteUserCommand message, CancellationToken cancellationToken)
        {
            var userFromRepo = await _userRepository.GetAsync(u => u.Id == message.UserId,
                                                              new string[] { "Facilities" });

            if (userFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate user");
            }

            if (_auditLogRepository.Exists(a => a.User.Id == message.UserId))
            {
                throw new DomainException("Unable to delete as item is in use");
            }

            var userFacilities = await _userFacilityRepository.ListAsync(c => c.User.Id == message.UserId);

            userFacilities.ToList().ForEach(userFacility => _userFacilityRepository.Delete(userFacility));

            _userRepository.Delete(userFromRepo);
            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- User {userFromRepo.Id} deleted");

            return(true);
        }
コード例 #7
0
        public async Task <LinkedCollectionResourceWrapperDto <CohortGroupDetailDto> > Handle(CohortGroupsDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <CohortGroup>(message.OrderBy, "asc");

            var pagedCohortGroupsFromRepo = await _cohortGroupRepository.ListAsync(pagingInfo, null, orderby, new string[] { "Condition", "CohortGroupEnrolments" });

            if (pagedCohortGroupsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCohortGroups = PagedCollection <CohortGroupDetailDto> .Create(_mapper.Map <PagedCollection <CohortGroupDetailDto> >(pagedCohortGroupsFromRepo),
                                                                                        pagingInfo.PageNumber,
                                                                                        pagingInfo.PageSize,
                                                                                        pagedCohortGroupsFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedCohortGroups.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <CohortGroupDetailDto>(pagedCohortGroupsFromRepo.TotalCount, mappedCohortGroups, pagedCohortGroupsFromRepo.TotalPages);

                CreateLinksForCohortGroups(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                           pagedCohortGroupsFromRepo.HasNext, pagedCohortGroupsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #8
0
        private async Task UpdateUserFacilitiesAsync(List <string> facilityNames, User userFromRepo)
        {
            var userFacilities = await _userFacilityRepository.ListAsync(uf => uf.User.Id == userFromRepo.Id, null, new string[] { "Facility" });

            var facilitiesToBeRemoved = PrepareFacilitiesToBeRemoved(facilityNames, userFacilities);
            var facilitiesToBeAdded   = await PrepareFacilitiesToBeAddedAsync(facilityNames, userFromRepo, userFacilities);

            facilitiesToBeRemoved.ForEach(userFacility => _userFacilityRepository.Delete(userFacility));
            facilitiesToBeAdded.ForEach(userFacility => _userFacilityRepository.Save(userFacility));
        }
コード例 #9
0
        public async Task <LinkedCollectionResourceWrapperDto <CustomAttributeDetailDto> > Handle(CustomAttributesDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <CustomAttributeConfiguration>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <CustomAttributeConfiguration>(true);

            if (message.ExtendableTypeName != ExtendableTypeNames.All)
            {
                predicate = predicate.And(f => f.ExtendableTypeName == message.ExtendableTypeName.ToString());
            }
            if (message.CustomAttributeType != CustomAttributeTypes.All)
            {
                predicate = predicate.And(f => f.CustomAttributeType.ToString() == message.CustomAttributeType.ToString());
            }
            if (message.IsSearchable.HasValue)
            {
                predicate = predicate.And(f => f.IsSearchable == message.IsSearchable);
            }

            var pagedCustomAttributesFromRepo = await _CustomAttributeRepository.ListAsync(pagingInfo, predicate, orderby, "");

            if (pagedCustomAttributesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCustomAttributes = PagedCollection <CustomAttributeDetailDto> .Create(_mapper.Map <PagedCollection <CustomAttributeDetailDto> >(pagedCustomAttributesFromRepo),
                                                                                                pagingInfo.PageNumber,
                                                                                                pagingInfo.PageSize,
                                                                                                pagedCustomAttributesFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                foreach (var mappedCustomAttribute in mappedCustomAttributes)
                {
                    CreateSelectionValues(mappedCustomAttribute);
                    CreateLinks(mappedCustomAttribute);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <CustomAttributeDetailDto>(pagedCustomAttributesFromRepo.TotalCount, mappedCustomAttributes, pagedCustomAttributesFromRepo.TotalPages);

                CreateLinksForCustomAttributes(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                               pagedCustomAttributesFromRepo.HasNext, pagedCustomAttributesFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #10
0
        private async Task <List <CohortGroupPatientDetailDto> > GetCohortGroupsAsync()
        {
            var cohortGroupsFromRepo = await _cohortGroupRepository.ListAsync(null, null, new string[] { "Condition" });

            if (cohortGroupsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCohortGroups = _mapper.Map <List <CohortGroupPatientDetailDto> >(cohortGroupsFromRepo);

                return(mappedCohortGroups);
            }

            return(null);
        }
コード例 #11
0
        public async Task <LinkedCollectionResourceWrapperDto <EnrolmentDetailDto> > Handle(CohortGroupEnrolmentsDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var cohortGroupFromRepo = await _cohortGroupRepository.GetAsync(cg => cg.Id == message.CohortGroupId);

            if (cohortGroupFromRepo == null)
            {
                throw new KeyNotFoundException($"Unable to locate cohort group {message.CohortGroupId}");
            }

            var orderby = Extensions.GetOrderBy <CohortGroupEnrolment>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <CohortGroupEnrolment>(true);

            predicate = predicate.And(cge => cge.CohortGroup.Id == message.CohortGroupId);

            var pagedCohortGroupEnrolmentsFromRepo = await _cohortGroupEnrolmentRepository.ListAsync(pagingInfo, predicate, orderby, new string[] {
                "CohortGroup",
                "Patient.PatientFacilities.Facility",
                "Patient.Encounters"
            });

            if (pagedCohortGroupEnrolmentsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCohortGroupEnrolments = PagedCollection <EnrolmentDetailDto> .Create(_mapper.Map <PagedCollection <EnrolmentDetailDto> >(pagedCohortGroupEnrolmentsFromRepo),
                                                                                               pagingInfo.PageNumber,
                                                                                               pagingInfo.PageSize,
                                                                                               pagedCohortGroupEnrolmentsFromRepo.TotalCount);

                foreach (var mappedCohortGroupEnrolment in mappedCohortGroupEnrolments)
                {
                    await CustomCohortGroupEnrolmentMapAsync(mappedCohortGroupEnrolment);

                    CreateLinks(mappedCohortGroupEnrolment);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <EnrolmentDetailDto>(pagedCohortGroupEnrolmentsFromRepo.TotalCount, mappedCohortGroupEnrolments, pagedCohortGroupEnrolmentsFromRepo.TotalPages);
                return(wrapper);
            }

            return(null);
        }
コード例 #12
0
        public async Task <LinkedCollectionResourceWrapperDto <ConditionDetailDto> > Handle(ConditionsDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <Condition>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <Condition>(true);

            if (message.Active != Models.ValueTypes.YesNoBothValueType.Both)
            {
                predicate = predicate.And(f => f.Active == (message.Active == Models.ValueTypes.YesNoBothValueType.Yes));
            }

            var pagedConditionsFromRepo = await _conditionRepository.ListAsync(pagingInfo, null, orderby, new string[] { "ConditionLabTests.LabTest", "ConditionMedDras.TerminologyMedDra", "ConditionMedications.Product", "ConditionMedications.Concept", "CohortGroups" });

            if (pagedConditionsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedConditions = PagedCollection <ConditionDetailDto> .Create(_mapper.Map <PagedCollection <ConditionDetailDto> >(pagedConditionsFromRepo),
                                                                                    pagingInfo.PageNumber,
                                                                                    pagingInfo.PageSize,
                                                                                    pagedConditionsFromRepo.TotalCount);

                foreach (var mappedCondition in mappedConditions)
                {
                    await CustomMapAsync(mappedCondition);
                }

                // Add HATEOAS links to each individual resource
                mappedConditions.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <ConditionDetailDto>(pagedConditionsFromRepo.TotalCount, mappedConditions, pagedConditionsFromRepo.TotalPages);

                CreateLinksForConditions(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                         pagedConditionsFromRepo.HasNext, pagedConditionsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #13
0
        private async Task <EnrolmentIdentifierDto> GetCohortGroupEnrolmentAsync(int cohortGroupId, int patientId)
        {
            var cohortGroupEnrolmentsFromRepo = await _cohortGroupEnrolmentRepository.ListAsync(cge => cge.CohortGroup.Id == cohortGroupId && cge.Patient.Id == patientId && !cge.Archived, null, new string[] { "CohortGroup" });

            if (cohortGroupEnrolmentsFromRepo != null)
            {
                if (cohortGroupEnrolmentsFromRepo.Count > 0)
                {
                    var cohortGroupEnrolment = cohortGroupEnrolmentsFromRepo.First();
                    // Map EF entity to Dto
                    var mappedCohortGroupEnrolment = _mapper.Map <EnrolmentIdentifierDto>(cohortGroupEnrolment);

                    return(mappedCohortGroupEnrolment);
                }
            }

            return(null);
        }
コード例 #14
0
        public async Task <LinkedCollectionResourceWrapperDto <ProductDetailDto> > Handle(ProductsDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <Product>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <Product>(true);

            if (message.Active != YesNoBothValueType.Both)
            {
                predicate = predicate.And(c => c.Active == (message.Active == YesNoBothValueType.Yes));
            }
            if (!String.IsNullOrWhiteSpace(message.SearchTerm))
            {
                predicate = predicate.And(c => c.ProductName.Contains(message.SearchTerm.Trim()));
            }

            var pagedProductsFromRepo = await _productRepository.ListAsync(pagingInfo, predicate, orderby, new string[] { "Concept.MedicationForm" });

            if (pagedProductsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedProducts = PagedCollection <ProductDetailDto> .Create(_mapper.Map <PagedCollection <ProductDetailDto> >(pagedProductsFromRepo),
                                                                                pagingInfo.PageNumber,
                                                                                pagingInfo.PageSize,
                                                                                pagedProductsFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedProducts.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <ProductDetailDto>(pagedProductsFromRepo.TotalCount, mappedProducts, pagedProductsFromRepo.TotalPages);

                CreateLinksForProducts(wrapper, message.OrderBy, message.SearchTerm, message.Active, message.PageNumber, message.PageSize,
                                       pagedProductsFromRepo.HasNext, pagedProductsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #15
0
        public async Task <LinkedCollectionResourceWrapperDto <UserIdentifierDto> > Handle(UsersIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <User>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <User>(true);

            if (!String.IsNullOrWhiteSpace(message.SearchTerm))
            {
                predicate = predicate.And(u => u.UserName.Contains(message.SearchTerm.Trim()) ||
                                          u.FirstName.Contains(message.SearchTerm.Trim()) ||
                                          u.LastName.Contains(message.SearchTerm.Trim()));
            }


            var pagedUsersFromRepo = await _userRepository.ListAsync(pagingInfo, predicate, orderby, "");

            if (pagedUsersFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedUsers = PagedCollection <UserIdentifierDto> .Create(_mapper.Map <PagedCollection <UserIdentifierDto> >(pagedUsersFromRepo),
                                                                              pagingInfo.PageNumber,
                                                                              pagingInfo.PageSize,
                                                                              pagedUsersFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedUsers.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <UserIdentifierDto>(pagedUsersFromRepo.TotalCount, mappedUsers, pagedUsersFromRepo.TotalPages);

                CreateLinksForUsers(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                    pagedUsersFromRepo.HasNext, pagedUsersFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #16
0
        public async Task <IEnumerable <NotificationDto> > Handle(NotificationsQuery message, CancellationToken cancellationToken)
        {
            var orderby = Extensions.GetOrderBy <Notification>("Created", "desc");

            var predicate = PredicateBuilder.New <Notification>(true);

            predicate = predicate.And(n => n.DestinationUserId == message.UserId);
            predicate = predicate.And(n => n.ValidUntilDate > DateTime.Now);

            var notificationsFromRepo = await _notificationRepository.ListAsync(predicate, orderby, new string[] { "" });

            if (notificationsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedNotifications = _mapper.Map <ICollection <NotificationDto> >(notificationsFromRepo);

                return(mappedNotifications);
            }

            return(null);
        }
コード例 #17
0
        public async Task <LinkedCollectionResourceWrapperDto <ConditionIdentifierDto> > Handle(ConditionsIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <Condition>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <Condition>(true);

            if (message.Active != Models.ValueTypes.YesNoBothValueType.Both)
            {
                predicate = predicate.And(f => f.Active == (message.Active == Models.ValueTypes.YesNoBothValueType.Yes));
            }

            var pagedConditionsFromRepo = await _conditionRepository.ListAsync(pagingInfo, null, orderby);

            if (pagedConditionsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedConditions = PagedCollection <ConditionIdentifierDto> .Create(_mapper.Map <PagedCollection <ConditionIdentifierDto> >(pagedConditionsFromRepo),
                                                                                        pagingInfo.PageNumber,
                                                                                        pagingInfo.PageSize,
                                                                                        pagedConditionsFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedConditions.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <ConditionIdentifierDto>(pagedConditionsFromRepo.TotalCount, mappedConditions, pagedConditionsFromRepo.TotalPages);

                CreateLinksForConditions(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                         pagedConditionsFromRepo.HasNext, pagedConditionsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
コード例 #18
0
        private async Task CustomMapAsync(ConditionDetailDto dto)
        {
            var cohortGroupsFromRepo = await _cohortGroupRepository.ListAsync(cg => cg.Condition.Id == dto.Id);

            dto.CohortGroups = _mapper.Map <PagedCollection <CohortGroupIdentifierDto> >(cohortGroupsFromRepo);
        }