Exemple #1
0
        private static CarePackageReclaim CreateReclaimEntity(CarePackageReclaimCreationDomain requestedReclaim, ReclaimSubType subType)
        {
            var fncPayment = requestedReclaim.ToEntity();

            fncPayment.Type       = ReclaimType.Fnc;
            fncPayment.SubType    = subType;
            fncPayment.Status     = ReclaimStatus.Active;
            fncPayment.Subjective = fncPayment.SubType == ReclaimSubType.FncPayment ? SubjectiveConstants.FncPaymentSubjectiveCode : SubjectiveConstants.FncReclaimSubjectiveCode;

            return(fncPayment);
        }
        public async Task <CarePackageReclaimResponse> CreateProvisionalCareCharge(CarePackageReclaimCreationDomain reclaimCreationDomain, ReclaimType reclaimType)
        {
            var carePackage = await _carePackageGateway
                              .GetPackageAsync(reclaimCreationDomain.CarePackageId, PackageFields.Details | PackageFields.Reclaims, true)
                              .EnsureExistsAsync($"Care package with id {reclaimCreationDomain.CarePackageId} not found");

            if (carePackage.Status.In(PackageStatus.Cancelled, PackageStatus.Ended))
            {
                throw new ApiException($"Can not create {reclaimType.GetDisplayName()} for care package status {carePackage.Status.GetDisplayName()}",
                                       HttpStatusCode.BadRequest);
            }

            var coreCostDetail = carePackage.Details
                                 .FirstOrDefault(d => d.Type is PackageDetailType.CoreCost)
                                 .EnsureExists($"Core cost for package with id {reclaimCreationDomain.CarePackageId} not found", HttpStatusCode.InternalServerError);

            ValidateProvisionalCareChargeAsync(reclaimCreationDomain, carePackage, coreCostDetail);

            //todo FK: ?
            reclaimCreationDomain.SubType = ReclaimSubType.CareChargeProvisional;
            var newReclaim = reclaimCreationDomain.ToEntity();

            //todo FK: ?
            newReclaim.Type       = ReclaimType.CareCharge;
            newReclaim.Status     = ReclaimStatus.Active;
            newReclaim.Subjective = SubjectiveConstants.CareChargeReclaimSubjectiveCode;

            carePackage.Reclaims.Add(newReclaim);

            carePackage.Histories.Add(new CarePackageHistory
            {
                Description = $"{reclaimType.GetDisplayName()} {reclaimCreationDomain.SubType.GetDisplayName()} Created",
            });

            // Change status of package to submitted for approval
            if (carePackage.Status == PackageStatus.Approved)
            {
                carePackage.Status = PackageStatus.SubmittedForApproval;
            }

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

            return(newReclaim.ToDomain().ToResponse());
        }