Exemplo n.º 1
0
        public Task <EnrolmentStatus> CreateEnrolmentStatusAsync(int enrolleeId, Status status)
        {
            ICollection <Status> availableStatuses      = new List <Status>();
            Enrollee             enrollee               = null;
            EnrolmentStatus      createdEnrolmentStatus = null;

            if (this.GetHolder <int, Enrollee>().ContainsKey(enrolleeId))
            {
                enrollee = this.GetHolder <int, Enrollee>()[enrolleeId];
                var currentStatusCode = enrollee.CurrentStatus?.StatusCode;

                if (this.IsStatusChangeAllowed(this.GetHolder <short, Status>()[currentStatusCode ?? NULL_STATUS_CODE], status))
                {
                    foreach (var item in enrollee.EnrolmentStatuses)
                    {
                        item.PharmaNetStatus = false;
                    }
                    createdEnrolmentStatus = new EnrolmentStatus {
                        Enrollee = enrollee, EnrolleeId = (int)enrollee.Id, Status = status, StatusCode = status.Code, StatusDate = DateTime.Now, PharmaNetStatus = false
                    };
                    enrollee.EnrolmentStatuses.Add(createdEnrolmentStatus);
                }
            }

            return(Task.FromResult(createdEnrolmentStatus));
        }
Exemplo n.º 2
0
        public EnrolmentStatusReasonFactory(EnrolmentStatus owner)
        {
            this.SetBaseRules();

            RuleFor(x => x.Id, f => IdCounter++);
            RuleFor(x => x.EnrolmentStatus, f => owner);
            RuleFor(x => x.EnrolmentStatusId, f => owner.Id);
            RuleFor(x => x.StatusReasonCode, f => f.PickRandom(StatusReasonLookup.All).Code);
            RuleFor(x => x.ReasonNote, f => f.Lorem.Paragraph(1).OrNull(f));

            Ignore(x => x.StatusReason);

            RuleSet("manualReason", (set) =>
            {
                set.RuleFor(x => x.StatusReasonCode, f => f.PickRandom(StatusReasonLookup.ManualReasons).Code);
            });
            RuleSet("manual", (set) =>
            {
                set.RuleFor(x => x.StatusReasonCode, f => StatusReasonLookup.Manual.Code);
            });
            RuleSet("automatic", (set) =>
            {
                set.RuleFor(x => x.StatusReasonCode, f => StatusReasonLookup.Automatic.Code);
            });
        }
Exemplo n.º 3
0
 private Enrollee EnrolleeWithCurrentStatus(StatusType type)
 {
     return(new Enrollee
     {
         EnrolmentStatuses = new[]
         {
             EnrolmentStatus.FromType(type, 0)
         }
     });
 }
Exemplo n.º 4
0
        private async Task <int?> CreateEnrolleeInternalAsync(Enrollee enrollee)
        {
            // Create a status history record
            EnrolmentStatus enrolmentStatus = new EnrolmentStatus {
                Enrollee = enrollee, StatusCode = Status.IN_PROGRESS_CODE, StatusDate = DateTime.Now, PharmaNetStatus = false
            };

            if (enrollee.EnrolmentStatuses == null)
            {
                enrollee.EnrolmentStatuses = new List <EnrolmentStatus>(0);
            }

            enrollee.EnrolmentStatuses.Add(enrolmentStatus);
            _context.Enrollees.Add(enrollee);

            var created = await _context.SaveChangesAsync();

            if (created < 1)
            {
                throw new InvalidOperationException("Could not create enrollee.");
            }

            return(enrollee.Id);
        }
Exemplo n.º 5
0
 public EnrolmentStatusModel(EnrolmentStatus model) : base(model)
 {
     Code = model.Code;
 }
Exemplo n.º 6
0
        private async Task <EnrolmentStatus> CreateEnrolmentStatusInternalAsync(int enrolleeId, Status status)
        {
            var enrollee = await this.GetBaseEnrolleeQuery()
                           .SingleOrDefaultAsync(e => e.Id == enrolleeId);

            if (enrollee == null)
            {
                return(null);
            }

            var currentStatus = enrollee.CurrentStatus?.Status;

            // Make sure the status change is allowed
            if (IsStatusChangeAllowed(currentStatus ?? NULL_STATUS, status))
            {
                // Create a new enrolment status
                var createdEnrolmentStatus = new EnrolmentStatus {
                    EnrolleeId = enrolleeId, StatusCode = status.Code, StatusDate = DateTime.Now, PharmaNetStatus = false
                };

                enrollee.EnrolmentStatuses.Add(createdEnrolmentStatus);

                switch (status?.Code)
                {
                case Status.SUBMITTED_CODE:
                    // Check to see if this should be auto adjudicated
                    if (_automaticAdjudicationService.QualifiesForAutomaticAdjudication(enrollee))
                    {
                        // Change the status to adjudicated/approved
                        createdEnrolmentStatus.PharmaNetStatus = false;
                        // Create a new approved enrolment status
                        var adjudicatedEnrolmentStatus = new EnrolmentStatus {
                            EnrolleeId = enrolleeId, StatusCode = Status.APPROVED_CODE, StatusDate = DateTime.Now, PharmaNetStatus = false
                        };
                        adjudicatedEnrolmentStatus.EnrolmentStatusReasons = new List <EnrolmentStatusReason> {
                            new EnrolmentStatusReason {
                                EnrolmentStatus = adjudicatedEnrolmentStatus, StatusReasonCode = StatusReason.AUTOMATIC_CODE
                            }
                        };
                        enrollee.EnrolmentStatuses.Add(adjudicatedEnrolmentStatus);
                        // Flip to the object that will get returned
                        createdEnrolmentStatus = adjudicatedEnrolmentStatus;
                    }
                    break;

                case Status.APPROVED_CODE:
                    // Add the manual reason code
                    createdEnrolmentStatus.EnrolmentStatusReasons = new List <EnrolmentStatusReason> {
                        new EnrolmentStatusReason {
                            EnrolmentStatus = createdEnrolmentStatus, StatusReasonCode = StatusReason.MANUAL_CODE
                        }
                    };
                    break;

                case Status.DECLINED_CODE:
                    await setAllPharmaNetStatusesFalseAsync(enrolleeId);

                    createdEnrolmentStatus.PharmaNetStatus = true;
                    break;

                case Status.ACCEPTED_TOS_CODE:
                    await setAllPharmaNetStatusesFalseAsync(enrolleeId);

                    enrollee.LicensePlate = this.GenerateLicensePlate();
                    createdEnrolmentStatus.PharmaNetStatus = true;
                    break;

                case Status.DECLINED_TOS_CODE:
                    await setAllPharmaNetStatusesFalseAsync(enrolleeId);

                    createdEnrolmentStatus.PharmaNetStatus = true;
                    break;
                }

                if (Status.ACCEPTED_TOS_CODE.Equals(status?.Code))
                {
                    enrollee.LicensePlate = this.GenerateLicensePlate();
                }

                var created = await _context.SaveChangesAsync();

                if (created < 1)
                {
                    throw new InvalidOperationException("Could not create enrolment status.");
                }

                // Enrollee just left manual adjudication, inform the enrollee
                if (currentStatus.Code == Status.SUBMITTED_CODE)
                {
                    _emailService.SendReminderEmail(enrollee);
                }

                return(createdEnrolmentStatus);
            }

            throw new InvalidOperationException("Could not create enrolment status, status change is not allowed.");
        }