Beispiel #1
0
        public async Task <IActionResult> DeleteCondition(int id)
        {
            var conditionFromRepo = await _conditionRepository.GetAsync(f => f.Id == id);

            if (conditionFromRepo == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var labTestValues = _unitOfWork.Repository <ConditionLabTest>().Queryable().Where(c => c.Condition.Id == id).ToList();
                labTestValues.ForEach(conditionLabTest => _conditionLabTestRepository.Delete(conditionLabTest));

                var medicationValues = _unitOfWork.Repository <ConditionMedication>().Queryable().Where(c => c.Condition.Id == id).ToList();
                medicationValues.ForEach(conditionMedication => _conditionMedicationRepository.Delete(conditionMedication));

                var meddraValues = _unitOfWork.Repository <ConditionMedDra>().Queryable().Where(c => c.Condition.Id == id).ToList();
                meddraValues.ForEach(conditionMedication => _conditionMeddraRepository.Delete(conditionMedication));

                _conditionRepository.Delete(conditionFromRepo);
                await _unitOfWork.CompleteAsync();
            }

            return(NoContent());
        }
        public async Task <IActionResult> DeleteEncounterType(long id)
        {
            var encounterTypeFromRepo = await _encounterTypeRepository.GetAsync(f => f.Id == id);

            if (encounterTypeFromRepo == null)
            {
                return(NotFound());
            }

            if (encounterTypeFromRepo.Encounters.Count > 0)
            {
                ModelState.AddModelError("Message", "Unable to delete as item is in use.");
            }

            if (ModelState.IsValid)
            {
                ICollection <EncounterTypeWorkPlan> deleteItems = new Collection <EncounterTypeWorkPlan>();
                foreach (var item in encounterTypeFromRepo.EncounterTypeWorkPlans)
                {
                    deleteItems.Add(item);
                }
                foreach (var item in deleteItems)
                {
                    _encounterTypeWorkPlanRepository.Delete(item);
                }

                _encounterTypeRepository.Delete(encounterTypeFromRepo);
                await _unitOfWork.CompleteAsync();

                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteMetaPage(long id)
        {
            var metaPageFromRepo = await _metaPageRepository.GetAsync(f => f.Id == id);

            if (metaPageFromRepo == null)
            {
                return(NotFound());
            }

            var pageInUse = _unitOfWork.Repository <MetaWidget>().Queryable()
                            .Any(w => w.MetaPage.Id == id);

            if (pageInUse)
            {
                ModelState.AddModelError("Message", "Unable to delete the page as it is currently in use.");
            }
            if (metaPageFromRepo.IsSystem)
            {
                ModelState.AddModelError("Message", "Unable to delete a system page");
            }

            if (ModelState.IsValid)
            {
                _metaPageRepository.Delete(metaPageFromRepo);
                await _unitOfWork.CompleteAsync();

                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
        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);
        }
Beispiel #5
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));
        }
        public async Task <IActionResult> DeleteDatasetElement(long id)
        {
            var datasetElementFromRepo = await _datasetElementRepository.GetAsync(f => f.Id == id, new string[] {
                "DatasetCategoryElements",
                "DatasetElementSubs",
                "Field.FieldValues"
            });

            if (datasetElementFromRepo == null)
            {
                return(NotFound());
            }

            if (datasetElementFromRepo.DatasetCategoryElements.Count > 0 ||
                datasetElementFromRepo.DatasetElementSubs.Count > 0 ||
                _unitOfWork.Repository <DatasetInstanceValue>()
                .Queryable()
                .Where(div => div.DatasetElement.Id == datasetElementFromRepo.Id)
                .Any())
            {
                ModelState.AddModelError("Message", "Unable to delete as item is in use.");
                return(BadRequest(ModelState));
            }

            if (ModelState.IsValid)
            {
                ICollection <FieldValue> deleteFieldValues = new Collection <FieldValue>();
                foreach (var fieldValue in datasetElementFromRepo.Field.FieldValues)
                {
                    deleteFieldValues.Add(fieldValue);
                }
                foreach (var fieldValue in deleteFieldValues)
                {
                    _fieldValueRepository.Delete(fieldValue);
                }

                ICollection <DatasetRule> deleteDatasetRules = new Collection <DatasetRule>();
                foreach (var datasetRule in datasetElementFromRepo.DatasetRules)
                {
                    deleteDatasetRules.Add(datasetRule);
                }
                foreach (var datasetRule in deleteDatasetRules)
                {
                    _datasetRuleRepository.Delete(datasetRule);
                }

                _datasetElementRepository.Delete(datasetElementFromRepo);
                _fieldRepository.Delete(datasetElementFromRepo.Field);

                await _unitOfWork.CompleteAsync();
            }

            return(NoContent());
        }
Beispiel #7
0
        public async Task <bool> Handle(DeleteCustomAttributeCommand message, CancellationToken cancellationToken)
        {
            var customAttributeFromRepo = await _customAttributeRepository.GetAsync(ca => ca.Id == message.Id, new string[] { "" });

            if (customAttributeFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate custom attribute");
            }

            _customAttributeRepository.Delete(customAttributeFromRepo);

            _logger.LogInformation($"----- Custom Attribute {message.Id} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Beispiel #8
0
        public async Task <IActionResult> DeleteLabResult(long id)
        {
            var labResultFromRepo = await _labResultRepository.GetAsync(f => f.Id == id);

            if (labResultFromRepo == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _labResultRepository.Delete(labResultFromRepo);
                await _unitOfWork.CompleteAsync();
            }

            return(NoContent());
        }
Beispiel #9
0
        public async Task <IActionResult> DeleteMetaWidget(long metaPageId, long id)
        {
            var metaWidgetFromRepo = await _metaWidgetRepository.GetAsync(f => f.MetaPage.Id == metaPageId && f.Id == id);

            if (metaWidgetFromRepo == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _metaWidgetRepository.Delete(metaWidgetFromRepo);
                await _unitOfWork.CompleteAsync();

                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
Beispiel #10
0
        public async Task <ActionResult <ExchangeRefreshTokenResponseModel> > RefreshToken([FromBody] ExchangeRefreshTokenRequest request)
        {
            if (request == null)
            {
                ModelState.AddModelError("Message", "Unable to locate payload for refresh token request");
                return(BadRequest(ModelState));
            }

            var userName        = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var userFromManager = await _userManager.FindByNameAsync(userName);

            var userFromRepo = await _userRepository.GetAsync(u => u.UserName == userName);

            if (userFromManager != null && userFromRepo != null)
            {
                if (userFromManager.Active == false)
                {
                    return(StatusCode(401, "User no longer active"));
                }

                if (userFromRepo.HasValidRefreshToken(request.RefreshToken))
                {
                    var jwtToken = await _jwtFactory.GenerateEncodedToken(userFromRepo, await _userManager.GetRolesAsync(userFromManager));

                    // delete existing refresh token
                    _refreshTokenRepository.Delete(userFromRepo.RefreshTokens.Single(a => a.Token == request.RefreshToken));

                    // generate refresh token
                    var refreshToken = _tokenFactory.GenerateToken();
                    userFromRepo.AddRefreshToken(refreshToken, HttpContext?.Connection?.RemoteIpAddress?.ToString());

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

                    return(new ExchangeRefreshTokenResponseModel()
                    {
                        AccessToken = jwtToken, RefreshToken = refreshToken
                    });
                }
            }

            return(StatusCode(404, "User does not have valid refresh token"));
        }
Beispiel #11
0
        public async Task <bool> Handle(DeleteFacilityCommand message, CancellationToken cancellationToken)
        {
            var facilityFromRepo = await _facilityRepository.GetAsync(f => f.Id == message.Id, new string[] { "PatientFacilities", "UserFacilities" });

            if (facilityFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate facility");
            }

            if (facilityFromRepo.PatientFacilities.Count > 0 || facilityFromRepo.UserFacilities.Count > 0)
            {
                throw new DomainException("Unable to delete the Facility as it is currently in use");
            }

            _facilityRepository.Delete(facilityFromRepo);

            _logger.LogInformation($"----- Facility {message.Id} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Beispiel #12
0
        public async Task <bool> Handle(DeleteCohortGroupCommand message, CancellationToken cancellationToken)
        {
            var cohortGroupFromRepo = await _cohortGroupRepository.GetAsync(cg => cg.Id == message.Id);

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

            if (_cohortGroupEnrolmentRepository.Exists(cge => cge.CohortGroup.Id == message.Id))
            {
                throw new DomainException("Unable to delete the Cohort Group as it is currently in use");
            }

            _cohortGroupRepository.Delete(cohortGroupFromRepo);

            _logger.LogInformation($"----- Cohort group {message.Id} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
        public async Task <bool> Handle(DeleteSelectionValueCommand message, CancellationToken cancellationToken)
        {
            var customAttributeFromRepo = await _customAttributeRepository.GetAsync(ca => ca.Id == message.CustomAttributeId, new string[] { "" });

            if (customAttributeFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate custom attribute");
            }

            var selectionDataItemFromRepo = await _selectionDataItemRepository.GetAsync(s => s.AttributeKey == customAttributeFromRepo.AttributeKey && s.SelectionKey == message.Key, new string[] { "" });

            if (selectionDataItemFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate selection data item");
            }

            _selectionDataItemRepository.Delete(selectionDataItemFromRepo);

            _logger.LogInformation($"----- Selection Data Item {message.Key} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Beispiel #14
0
        public async Task <bool> Handle(DeleteProductCommand message, CancellationToken cancellationToken)
        {
            var productFromRepo = await _productRepository.GetAsync(p => p.Id == message.ProductId, new string[] {
                "ConditionMedications",
                "PatientMedications"
            });

            if (productFromRepo == null)
            {
                throw new KeyNotFoundException($"Unable to locate product {message.ProductId}");
            }

            if (productFromRepo.ConditionMedications.Count() > 0 || productFromRepo.PatientMedications.Count() > 0)
            {
                throw new DomainException("Unable to delete product as it is currently in use");
            }

            _productRepository.Delete(productFromRepo);

            _logger.LogInformation($"----- Product {message.ProductId} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Beispiel #15
0
        public async Task <IActionResult> DeleteCareEvent(long id)
        {
            var careEventFromRepo = await _careEventRepository.GetAsync(f => f.Id == id);

            if (careEventFromRepo == null)
            {
                return(NotFound());
            }

            if (careEventFromRepo.WorkPlanCareEvents.Count > 0)
            {
                ModelState.AddModelError("Message", "Unable to delete as item is in use.");
                return(BadRequest(ModelState));
            }

            if (ModelState.IsValid)
            {
                _careEventRepository.Delete(careEventFromRepo);
                await _unitOfWork.CompleteAsync();
            }

            return(NoContent());
        }
Beispiel #16
0
        public async Task <IActionResult> DeleteMetaReport(long id)
        {
            var metaReportFromRepo = await _metaReportRepository.GetAsync(f => f.Id == id);

            if (metaReportFromRepo == null)
            {
                return(NotFound());
            }

            if (metaReportFromRepo.IsSystem)
            {
                ModelState.AddModelError("Message", "Unable to delete a system report");
            }

            if (ModelState.IsValid)
            {
                _metaReportRepository.Delete(metaReportFromRepo);
                await _unitOfWork.CompleteAsync();

                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
Beispiel #17
0
        public void RemoveSelectionDataItem(long selectionDataItemId)
        {
            var deleteItem = _selectionDataItemRepository.Get(selectionDataItemId);

            _selectionDataItemRepository.Delete(deleteItem);
        }