Ejemplo n.º 1
0
        public async Task UpdateAsync(CarePackageReclaimUpdateDomain requestedReclaim, Guid packageId)
        {
            var package = await _carePackageGateway
                          .GetPackageAsync(packageId, PackageFields.Resources | PackageFields.Details | PackageFields.Reclaims, true)
                          .EnsureExistsAsync($"Care package {packageId} not found");

            var reclaims = package.Reclaims
                           .Where(reclaim =>
                                  reclaim.Status != ReclaimStatus.Cancelled &&
                                  reclaim.Type == ReclaimType.Fnc).ToList();

            var fncPayment = reclaims.SingleOrDefault(r => r.SubType is ReclaimSubType.FncPayment);
            var fncReclaim = reclaims.SingleOrDefault(r => r.SubType is ReclaimSubType.FncReclaim);


            if (fncPayment is null || fncReclaim is null)
            {
                throw new ApiException($"No FNC defined for package {packageId}", HttpStatusCode.NotFound);
            }

            if (requestedReclaim.HasAssessmentBeenCarried)
            {
                var fncReclaimId = fncReclaim.Id;

                _mapper.Map(requestedReclaim, fncPayment);
                _mapper.Map(requestedReclaim, fncReclaim);

                fncReclaim.Id   = fncReclaimId;
                fncReclaim.Cost = Decimal.Negate(fncPayment.Cost);

                fncPayment.Subjective = SubjectiveConstants.FncPaymentSubjectiveCode;
                fncReclaim.Subjective = SubjectiveConstants.FncReclaimSubjectiveCode;

                ReclaimCostValidator.Validate(package);

                await using (var transaction = await _dbManager.BeginTransactionAsync())
                {
                    if (requestedReclaim.AssessmentFileId.IsEmpty() && requestedReclaim.AssessmentFile != null)
                    {
                        await _createPackageResourceUseCase.CreateFileAsync(
                            package.Id, PackageResourceType.FncAssessmentFile, requestedReclaim.AssessmentFile);
                    }

                    await _dbManager.SaveAsync();

                    await transaction.CommitAsync();
                }
            }
            else
            {
                fncPayment.Status = ReclaimStatus.Cancelled;
                fncReclaim.Status = ReclaimStatus.Cancelled;

                await _dbManager.SaveAsync();
            }
        }
        public async Task <CarePackagePlainResponse> UpdateAsync(Guid carePackageId, CarePackageUpdateDomain carePackageUpdateDomain)
        {
            var package = await _carePackageGateway.GetPackagePlainAsync(carePackageId, true).EnsureExistsAsync($"Care package with id {carePackageId} not found");

            await _ensureSingleActivePackageTypePerUserUseCase.ExecuteAsync(package.ServiceUserId, carePackageUpdateDomain.PackageType, package.Id);

            var packageSettings = await _carePackageSettings.GetPackageSettingsPlainAsync(carePackageId, true) ?? new CarePackageSettings
            {
                CarePackageId         = package.Id,
                HasRespiteCare        = false,
                HasDischargePackage   = false,
                HospitalAvoidance     = false,
                IsReEnablement        = false,
                IsS117Client          = false,
                IsS117ClientConfirmed = false
            };

            var allowedPackageStatuses = new[] { PackageStatus.New, PackageStatus.InProgress };

            if (package.PackageType != carePackageUpdateDomain.PackageType && !allowedPackageStatuses.Contains(package.Status))
            {
                throw new ApiException(
                          $"Failed to update package. Package type cannot be changed for package with status {package.Status.GetDisplayName()}", HttpStatusCode.BadRequest);
            }

            if (package.PackageType != carePackageUpdateDomain.PackageType && carePackageUpdateDomain.PackageType == PackageType.ResidentialCare)
            {
                // Delete funded nursing care if added to package
                await _carePackageGateway.DeleteReclaimsForPackage(carePackageId, ReclaimType.Fnc);
            }

            if (carePackageUpdateDomain.SocialWorkerCarePlanFileId == null && carePackageUpdateDomain.SocialWorkerCarePlanFile != null)
            {
                await _createPackageResourceUseCase.CreateFileAsync(carePackageId, PackageResourceType.CarePlanFile, carePackageUpdateDomain.SocialWorkerCarePlanFile);
            }

            // Update values
            _mapper.Map(carePackageUpdateDomain, package);
            package.Status = PackageStatus.InProgress; // Change status of package to in-progress
            _mapper.Map(carePackageUpdateDomain, packageSettings);
            package.Settings = packageSettings;

            // Save values
            await _dbManager.SaveAsync($"Failed to update care package with id {carePackageId}");

            return(package.ToPlainDomain().ToResponse());
        }
Ejemplo n.º 3
0
        public async Task <CarePackageReclaimResponse> ExecuteAsync(CarePackageReclaimCreationDomain requestedReclaim)
        {
            var package = await _carePackageGateway
                          .GetPackageAsync(requestedReclaim.CarePackageId, PackageFields.Details | PackageFields.Reclaims, true)
                          .EnsureExistsAsync($"Care package {requestedReclaim.CarePackageId} not found");

            ValidateReclaim(requestedReclaim, package);

            // two FNC items are created
            // - one for the real payment to home, which will be included in Core Cost
            // - another one is for reclaim, with negative amount, which will compensate payment item.
            // Just item with FNCPayment sub-type is used in UI / brokerage, reclaim item is for invoicing
            var fncPayment = CreateReclaimEntity(requestedReclaim, ReclaimSubType.FncPayment);
            var fncReclaim = CreateReclaimEntity(requestedReclaim, ReclaimSubType.FncReclaim);

            fncReclaim.Cost = Decimal.Negate(requestedReclaim.Cost);

            package.Reclaims.Add(fncPayment);
            package.Reclaims.Add(fncReclaim);

            package.Histories.Add(new CarePackageHistory {
                Description = "FNC Created"
            });

            if (package.Status is PackageStatus.Approved)
            {
                package.Status = PackageStatus.SubmittedForApproval;
            }

            ReclaimCostValidator.Validate(package);

            await using (var transaction = await _dbManager.BeginTransactionAsync())
            {
                await _createPackageResourceUseCase.CreateFileAsync(
                    package.Id, PackageResourceType.FncAssessmentFile, requestedReclaim.AssessmentFile);

                await _dbManager.SaveAsync("Could not save FNC reclaim to database");

                await transaction.CommitAsync();
            }

            return(fncPayment.ToDomain().ToResponse());
        }
        public async Task <ActionResult> UploadCareChargeAssessmentFile([FromServices] ICreatePackageResourceUseCase useCase, Guid carePackageId)
        {
            try
            {
                var formCollection = await Request.ReadFormAsync();

                var file = formCollection.Files[0];

                if (file == null)
                {
                    throw new ApiException($"Please select a file and try again", HttpStatusCode.BadRequest);
                }

                var resourceId =
                    await useCase.CreateFileAsync(carePackageId, PackageResourceType.CareChargeAssessmentFile, file);

                return(Ok(resourceId));
            }
            catch (Exception e)
            {
                throw new ApiException($"An error occurred: {e.Message} {e.InnerException?.Message}");
            }
        }