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

            var existingReclaim = package.Reclaims
                                  .SingleOrDefault(r => r.Id == requestedReclaim.Id)
                                  .EnsureExists($"Care package reclaim {requestedReclaim.Id} not found");

            ValidateRequest(existingReclaim, package);

            if (ShouldReplaceReclaim(existingReclaim, requestedReclaim))
            {
                var newReclaim = requestedReclaim.ToEntity();

                newReclaim.Id         = Guid.Empty;
                newReclaim.Type       = existingReclaim.Type;
                newReclaim.SubType    = existingReclaim.SubType;
                newReclaim.Subjective = existingReclaim.Subjective;
                newReclaim.Status     = newReclaim.Status; // persist calculated value for new record

                package.Reclaims.Add(newReclaim);

                existingReclaim.Status = ReclaimStatus.Cancelled;
            }
            else
            {
                _mapper.Map(requestedReclaim, existingReclaim);
            }

            ReclaimCostValidator.Validate(package);

            await _dbManager.SaveAsync("Could not update care package reclaim");
        }
Beispiel #2
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();
            }
        }
Beispiel #3
0
        public void ShouldFailWhenReclaimsExceedsCoreCost()
        {
            var package = TestDataHelper
                          .CreateCarePackage()
                          .AddCoreCost(1000.0m, "01-12-2022", "31-12-2022")
                          .AddCareChargeProvisional(2500.0m, ClaimCollector.Supplier, "01-12-2022", "31-12-2022")
                          .SetCurrentDate("01-12-2022");

            FluentActions.Invoking(() =>
                                   ReclaimCostValidator.Validate(package)).Should().Throw <ApiException>();
        }
Beispiel #4
0
        public void ShouldPassWhenReclaimsLessThanCosts()
        {
            var package = TestDataHelper
                          .CreateCarePackage()
                          .AddCoreCost(1000.0m, "01-12-2022", "31-12-2022")
                          .AddWeeklyNeed(500.0m, "01-12-2022", "15-12-2022")
                          .AddCareChargeProvisional(250.0m, ClaimCollector.Supplier, "01-12-2022", "31-12-2022")
                          .SetCurrentDate("01-12-2022");

            FluentActions.Invoking(() =>
                                   ReclaimCostValidator.Validate(package)).Should().NotThrow();
        }
Beispiel #5
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 ExecuteAsync(Guid carePackageId, CareChargesCreateDomain request)
        {
            // Get package with all reclaims
            var package = await _carePackageGateway
                          .GetPackageAsync(carePackageId, PackageFields.Settings | PackageFields.Details | PackageFields.Reclaims, true)
                          .EnsureExistsAsync($"Care package with id {carePackageId} not found");

            ValidatePackage(package);
            ValidateRequestIntegrity(request, package); // ensure existing reclaims match requested

            // since validating raw request is tricky, first build a model of ordered charges
            // and then validate them to be in package date range and followed each other without any gaps
            PrepareCareChargesModel(request, package);
            ValidateCareChargesModel(request, package);

            // if care charge has date / cost / collector changed, cancel existing one and replace it with new.
            ReplaceUpdatedCareCharges(request, package);
            ReclaimCostValidator.Validate(package);

            await _dbManager.SaveAsync();
        }