Exemplo n.º 1
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);
        }
        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);
        }
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get auditLogs from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="auditLogResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private ICollection <T> GetAuditLogsForExtract <T>(AuditLogResourceParameters auditLogResourceParameters) where T : class
        {
            var orderby = Extensions.GetOrderBy <AuditLog>(auditLogResourceParameters.OrderBy, "asc");

            // FIlter audit logs
            var predicate = PredicateBuilder.New <AuditLog>(true);

            predicate = predicate.And(au => au.ActionDate >= auditLogResourceParameters.SearchFrom && au.ActionDate <= auditLogResourceParameters.SearchTo);

            switch (auditLogResourceParameters.AuditType)
            {
            case AuditTypeFilter.SubscriberAccess:
                predicate = predicate.And(au => au.AuditType == AuditType.InvalidSubscriberAccess || au.AuditType == AuditType.ValidSubscriberAccess);
                break;

            case AuditTypeFilter.SubscriberPost:
                predicate = predicate.And(au => au.AuditType == AuditType.InValidSubscriberPost || au.AuditType == AuditType.ValidSubscriberPost);
                break;

            case AuditTypeFilter.MeddraImport:
                predicate = predicate.And(au => au.AuditType == AuditType.InValidMedDRAImport || au.AuditType == AuditType.ValidMedDRAImport);
                break;

            case AuditTypeFilter.UserLogin:
                predicate = predicate.And(au => au.AuditType == AuditType.UserLogin);
                break;

            case AuditTypeFilter.SynchronisationSuccessful:
                predicate = predicate.And(au => au.AuditType == AuditType.SynchronisationForm);
                break;

            case AuditTypeFilter.SynchronisationError:
                predicate = predicate.And(au => au.AuditType == AuditType.SynchronisationError);
                break;
            }

            if (auditLogResourceParameters.FacilityId > 0)
            {
                predicate = predicate.And(au => au.User.Facilities.Any(uf => uf.Facility.Id == auditLogResourceParameters.FacilityId));
            }

            var auditLogsFromRepo = _auditLogRepository.List(predicate, orderby, "");

            if (auditLogsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedAuditLogs = _mapper.Map <ICollection <T> >(auditLogsFromRepo);

                return(mappedAuditLogs);
            }

            return(null);
        }
        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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get lab results from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="labResultResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetLabResults <T>(LabResultResourceParameters labResultResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = labResultResourceParameters.PageNumber,
                PageSize   = labResultResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <LabResult>(labResultResourceParameters.OrderBy, "asc");

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

            if (!String.IsNullOrWhiteSpace(labResultResourceParameters.SearchTerm))
            {
                predicate = predicate.And(f => f.Description.Contains(labResultResourceParameters.SearchTerm.Trim()));
            }
            if (labResultResourceParameters.Active != Models.ValueTypes.YesNoBothValueType.Both)
            {
                predicate = predicate.And(f => f.Active == (labResultResourceParameters.Active == Models.ValueTypes.YesNoBothValueType.Yes));
            }

            var pagedLabResultsFromRepo = _labResultRepository.List(pagingInfo, predicate, orderby, "");

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedLabResults.TotalCount,
                    pageSize    = mappedLabResults.PageSize,
                    currentPage = mappedLabResults.CurrentPage,
                    totalPages  = mappedLabResults.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedLabResults);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get dataset elements from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="datasetElementResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetDatasetElements <T>(DatasetElementResourceParameters datasetElementResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = datasetElementResourceParameters.PageNumber,
                PageSize   = datasetElementResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <DatasetElement>(datasetElementResourceParameters.OrderBy, "asc");

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

            if (!String.IsNullOrWhiteSpace(datasetElementResourceParameters.ElementName))
            {
                predicate = predicate.And(f => f.ElementName.Contains(datasetElementResourceParameters.ElementName));
            }

            var pagedDatasetElementsFromRepo = _datasetElementRepository.List(pagingInfo, predicate, orderby, new string[] {
                "Field.FieldType"
            });

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedDatasetElements.TotalCount,
                    pageSize    = mappedDatasetElements.PageSize,
                    currentPage = mappedDatasetElements.CurrentPage,
                    totalPages  = mappedDatasetElements.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedDatasetElements);
            }

            return(null);
        }
        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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get patients from auditLogs
        /// </summary>
        /// <param name="auditLogResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private List <long> GetPatientsFromAuditLogs(AuditLogResourceParameters auditLogResourceParameters)
        {
            var orderby = Extensions.GetOrderBy <AuditLog>(auditLogResourceParameters.OrderBy, "asc");

            // FIlter audit logs
            var predicate = PredicateBuilder.New <AuditLog>(true);

            predicate = predicate.And(au => au.ActionDate >= auditLogResourceParameters.SearchFrom && au.ActionDate <= auditLogResourceParameters.SearchTo);
            predicate = predicate.And(au => au.AuditType == AuditType.SynchronisationForm);

            if (auditLogResourceParameters.FacilityId > 0)
            {
                predicate = predicate.And(au => au.User.Facilities.Any(uf => uf.Facility.Id == auditLogResourceParameters.FacilityId));
            }

            var auditLogsFromRepo = _auditLogRepository.List(predicate, orderby, "");

            if (auditLogsFromRepo != null)
            {
                var returnIds = new List <long>();
                foreach (var auditLog in auditLogsFromRepo)
                {
                    // Extract form identifier
                    var formIdentifier = auditLog.Details.Replace("Form submission successful ", "");

                    // Locate patient
                    if (!string.IsNullOrWhiteSpace(formIdentifier))
                    {
                        var attachments = _attachmentRepository.List(a => a.Patient != null && a.Description == formIdentifier);
                        if (attachments.Count > 0)
                        {
                            var patient = attachments.First()?.Patient;
                            if (patient != null)
                            {
                                returnIds.Add(patient.Id);
                            }
                        }
                    }
                }

                return(returnIds);
            }

            return(null);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get common meddra terms from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="meddraTermResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetCommonMeddraTerms <T>(MeddraTermResourceParameters meddraTermResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = meddraTermResourceParameters.PageNumber,
                PageSize   = meddraTermResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <TerminologyMedDra>(meddraTermResourceParameters.OrderBy, "asc");

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

            predicate = predicate.And(mt => mt.Common == true);

            var pagedTermsFromRepo = _termsRepository.List(pagingInfo, predicate, orderby, "");

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedTerms.TotalCount,
                    pageSize    = mappedTerms.PageSize,
                    currentPage = mappedTerms.CurrentPage,
                    totalPages  = mappedTerms.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedTerms);
            }

            return(null);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get risk factors from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="riskFactorResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetRiskFactors <T>(IdResourceParameters riskFactorResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = riskFactorResourceParameters.PageNumber,
                PageSize   = riskFactorResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <RiskFactor>(riskFactorResourceParameters.OrderBy, "asc");

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

            predicate = predicate.And(f => f.Active);

            var pagedRiskFactorsFromRepo = _riskFactorRepository.List(pagingInfo, predicate, orderby, "");

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedRiskFactors.TotalCount,
                    pageSize    = mappedRiskFactors.PageSize,
                    currentPage = mappedRiskFactors.CurrentPage,
                    totalPages  = mappedRiskFactors.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedRiskFactors);
            }

            return(null);
        }
Exemplo n.º 14
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);
        }
        private async Task <LinkedCollectionResourceWrapperDto <ReportInstanceDetailDto> > GetReportInstancesAsync(
            Guid workFlowGuid,
            int pageNumber,
            int pageSize,
            string qualifiedName)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = pageNumber,
                PageSize   = pageSize
            };

            var orderby   = Extensions.GetOrderBy <ReportInstance>("Created", "desc");
            var predicate = await PreparePredicateForFilter(workFlowGuid, qualifiedName);

            var pagedReportsFromRepo = _reportInstanceRepository.List(pagingInfo, predicate, orderby, new string[] { "WorkFlow", "Medications", "TerminologyMedDra", "Activities.CurrentStatus", "Activities.ExecutionEvents.ExecutionStatus", "Tasks" });

            if (pagedReportsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedReportsWithLinks = new List <ReportInstanceDetailDto>();

                foreach (var pagedReport in pagedReportsFromRepo)
                {
                    var mappedReport = _mapper.Map <ReportInstanceDetailDto>(pagedReport);

                    await CustomMapAsync(pagedReport, mappedReport);
                    await CreateLinksAsync(pagedReport, mappedReport);

                    mappedReportsWithLinks.Add(mappedReport);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <ReportInstanceDetailDto>(pagedReportsFromRepo.TotalCount, mappedReportsWithLinks, pagedReportsFromRepo.TotalPages);

                CreateLinksForReportInstances(workFlowGuid, wrapper, "Created", "", DateTime.MinValue, DateTime.MaxValue, pageNumber, pageSize,
                                              pagedReportsFromRepo.HasNext, pagedReportsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Exemplo n.º 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);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get lab results from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="configResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetConfigs <T>(ConfigResourceParameters configResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = configResourceParameters.PageNumber,
                PageSize   = configResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <Config>(configResourceParameters.OrderBy, "asc");

            var pagedConfigsFromRepo = _configRepository.List(pagingInfo, null, orderby, "");

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedConfigs.TotalCount,
                    pageSize    = mappedConfigs.PageSize,
                    currentPage = mappedConfigs.CurrentPage,
                    totalPages  = mappedConfigs.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedConfigs);
            }

            return(null);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Get meta tables from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="metaResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        PagedCollection <T> GetMetaReports <T>(IdResourceParameters metaResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = metaResourceParameters.PageNumber,
                PageSize   = metaResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <MetaReport>(metaResourceParameters.OrderBy, "asc");

            var reportdMetaReportsFromRepo = _metaReportRepository.List(pagingInfo, null, orderby, "");

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount    = mappedMetaReports.TotalCount,
                    reportSize    = mappedMetaReports.PageSize,
                    currentReport = mappedMetaReports.CurrentPage,
                    totalReports  = mappedMetaReports.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedMetaReports);
            }

            return(null);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Get roles from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="baseResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetRoles <T>(IdResourceParameters baseResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = baseResourceParameters.PageNumber,
                PageSize   = baseResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <IdentityRole <Guid> >(baseResourceParameters.OrderBy, "asc");

            var rolesFromManager = _roleManager.Roles.ToList();

            if (rolesFromManager != null)
            {
                // Map EF entity to Dto
                var mappedRoles = PagedCollection <T> .Create(_mapper.Map <PagedCollection <T> >(rolesFromManager),
                                                              pagingInfo.PageNumber,
                                                              pagingInfo.PageSize,
                                                              rolesFromManager.Count);

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedRoles.TotalCount,
                    pageSize    = mappedRoles.PageSize,
                    currentPage = mappedRoles.CurrentPage,
                    totalPages  = mappedRoles.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

                return(mappedRoles);
            }

            return(null);
        }
        private async Task <LinkedCollectionResourceWrapperDto <ReportInstanceDetailDto> > GetReportInstancesAsync(
            Guid workFlowGuid,
            int pageNumber,
            int pageSize,
            string qualifiedName)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = pageNumber,
                PageSize   = pageSize
            };

            var orderby = Extensions.GetOrderBy <ReportInstance>("Created", "desc");

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

            predicate = predicate.And(r => r.WorkFlow.WorkFlowGuid == workFlowGuid);

            if (!String.IsNullOrWhiteSpace(qualifiedName))
            {
                switch (qualifiedName)
                {
                case "Confirm Report Data":
                    predicate = predicate.And(f => f.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == true && a.CurrentStatus.Description != "DELETED"));
                    break;

                case "Extract E2B":
                    predicate = predicate.And(f => f.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == true && a.CurrentStatus.Description != "E2BSUBMITTED"));
                    break;

                default:
                    predicate = predicate.And(f => f.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == true));
                    break;
                }
            }
            else
            {
                (DateTime searchFrom, DateTime searchTo) = await PrepareComparisonDateRangeAsync();

                predicate = predicate.And(f => f.Created >= searchFrom && f.Created <= searchTo);
            }

            var pagedReportsFromRepo = _reportInstanceRepository.List(pagingInfo, predicate, orderby, new string[] { "WorkFlow", "Medications", "TerminologyMedDra", "Activities.CurrentStatus", "Activities.ExecutionEvents.ExecutionStatus", "Activities.ExecutionEvents.Attachments", "Tasks" });

            if (pagedReportsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedReportsWithLinks = new List <ReportInstanceDetailDto>();

                foreach (var pagedReport in pagedReportsFromRepo)
                {
                    var mappedReport = _mapper.Map <ReportInstanceDetailDto>(pagedReport);

                    await CustomMapAsync(pagedReport, mappedReport);
                    await CreateLinksAsync(pagedReport, mappedReport);

                    mappedReportsWithLinks.Add(mappedReport);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <ReportInstanceDetailDto>(pagedReportsFromRepo.TotalCount, mappedReportsWithLinks, pagedReportsFromRepo.TotalPages);

                CreateLinksForReportInstances(workFlowGuid, wrapper, "Created", "", DateTime.MinValue, DateTime.MaxValue, pageNumber, pageSize,
                                              pagedReportsFromRepo.HasNext, pagedReportsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Get auditLogs from repository and auto map to Dto
        /// </summary>
        /// <typeparam name="T">Identifier or detail Dto</typeparam>
        /// <param name="auditLogResourceParameters">Standard parameters for representing resource</param>
        /// <returns></returns>
        private PagedCollection <T> GetAuditLogs <T>(AuditLogResourceParameters auditLogResourceParameters) where T : class
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = auditLogResourceParameters.PageNumber,
                PageSize   = auditLogResourceParameters.PageSize
            };

            var orderby = Extensions.GetOrderBy <AuditLog>(auditLogResourceParameters.OrderBy, "asc");

            // FIlter audit logs
            var predicate = PredicateBuilder.New <AuditLog>(true);

            predicate = predicate.And(au => au.ActionDate >= auditLogResourceParameters.SearchFrom && au.ActionDate <= auditLogResourceParameters.SearchTo);

            switch (auditLogResourceParameters.AuditType)
            {
            case AuditTypeFilter.SubscriberAccess:
                predicate = predicate.And(au => au.AuditType == AuditType.InvalidSubscriberAccess || au.AuditType == AuditType.ValidSubscriberAccess);
                break;

            case AuditTypeFilter.SubscriberPost:
                predicate = predicate.And(au => au.AuditType == AuditType.InValidSubscriberPost || au.AuditType == AuditType.ValidSubscriberPost);
                break;

            case AuditTypeFilter.MeddraImport:
                predicate = predicate.And(au => au.AuditType == AuditType.InValidMedDRAImport || au.AuditType == AuditType.ValidMedDRAImport);
                break;

            case AuditTypeFilter.UserLogin:
                predicate = predicate.And(au => au.AuditType == AuditType.UserLogin);
                break;

            case AuditTypeFilter.SynchronisationSuccessful:
                predicate = predicate.And(au => au.AuditType == AuditType.SynchronisationForm);
                break;

            case AuditTypeFilter.SynchronisationError:
                predicate = predicate.And(au => au.AuditType == AuditType.SynchronisationError);
                break;

            case AuditTypeFilter.DataValidation:
                predicate = predicate.And(au => au.AuditType == AuditType.DataValidation);
                break;
            }

            if (auditLogResourceParameters.FacilityId > 0)
            {
                predicate = predicate.And(au => au.User.Facilities.Any(uf => uf.Facility.Id == auditLogResourceParameters.FacilityId));
            }

            var pagedAuditLogsFromRepo = _auditLogRepository.List(pagingInfo, predicate, orderby, new string[] { "User" });

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

                // Prepare pagination data for response
                var paginationMetadata = new
                {
                    totalCount  = mappedAuditLogs.TotalCount,
                    pageSize    = mappedAuditLogs.PageSize,
                    currentPage = mappedAuditLogs.CurrentPage,
                    totalPages  = mappedAuditLogs.TotalPages,
                };

                Response.Headers.Add("X-Pagination",
                                     JsonConvert.SerializeObject(paginationMetadata));

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

                return(mappedAuditLogs);
            }

            return(null);
        }