private rscd_Establishment GetOrCreateEstablishment(CheckingWindow checkingWindow, string id)
        {
            using (var context = new CrmServiceContext(_organizationService))
            {
                var establishmentDto =
                    context.rscd_EstablishmentSet.SingleOrDefault(
                        e => e.rscd_URN == id);
                if (establishmentDto == null)
                {
                    establishmentDto =
                        context.rscd_EstablishmentSet.SingleOrDefault(
                            e => e.rscd_LAEstab == id);
                }

                if (establishmentDto != null)
                {
                    return(establishmentDto);
                }

                School establishment = null;
                try
                {
                    establishment = _establishmentService.GetByURN(checkingWindow, new URN(id));
                }
                catch
                {
                }

                if (establishment == null)
                {
                    establishment = _establishmentService.GetByDFESNumber(checkingWindow, id);
                }

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


                establishmentDto = new rscd_Establishment()
                {
                    rscd_Name               = establishment.SchoolName,
                    rscd_URN                = establishment.Urn.Value,
                    rscd_LAEstab            = establishment.DfesNumber.ToString(),
                    rscd_Schooltype         = establishment.SchoolType,
                    rscd_NumberofAmendments = 0
                };
                context.AddObject(establishmentDto);
                var result = context.SaveChanges();
                if (result.HasError)
                {
                    throw result.FirstOrDefault(e => e.Error != null)?.Error ?? new ApplicationException();
                }

                return(establishmentDto);
            }
        }
        public IActionResult Search(
            [FromQuery][SwaggerParameter("Event search criteria.", Required = true)]
            EstablishmentsSearchRequest request,
            [FromRoute][SwaggerParameter("The checking window to request amendments from", Required = true)]
            CheckingWindow checkingWindow)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var establishmentData = _establishmentService.GetByDFESNumber(checkingWindow, request.DFESNumber);
            var response          = new GetResponse <School>
            {
                Result = establishmentData,
                Error  = new Error()
            };

            return(Ok(response));
        }
        protected override AmendmentOutcome ApplyRule(Amendment amendment)
        {
            var laestabAnswer = GetAnswer(amendment, nameof(LaestabNumberQuestion));

            var establishment = _establishmentService
                                .GetByDFESNumber(amendment.CheckingWindow, laestabAnswer.Value);

            var evidenceUploadAnswer = GetAnswer(amendment, nameof(EvidenceUploadQuestion));

            amendment.EvidenceStatus =
                string.IsNullOrEmpty(evidenceUploadAnswer.Value) || evidenceUploadAnswer.Value == "0"
                    ? EvidenceStatus.Later
                    : EvidenceStatus.Now;

            return(new AmendmentOutcome(OutcomeStatus.AwatingDfeReview, null)
            {
                ScrutinyStatusCode = ScrutinyCode.ToString(),
                ReasonId = (int)AmendmentReasonCode.DualRegistration,
                ReasonDescription = ReasonDescription
            });
        }
Exemple #4
0
        protected override AmendmentOutcome ApplyRule(Amendment amendment)
        {
            var laestabAnswer = GetAnswer(amendment, nameof(LaestabNumberQuestion));

            var establishment = _establishmentService
                                .GetByDFESNumber(amendment.CheckingWindow, laestabAnswer.Value);

            var pupilExclusionDate = GetAnswer(amendment, nameof(PupilExclusionDateQuestion));

            var evidenceUploadAnswer = GetAnswer(amendment, nameof(EvidenceUploadQuestion));

            amendment.EvidenceStatus = string.IsNullOrEmpty(evidenceUploadAnswer.Value) || evidenceUploadAnswer.Value == "0"
                ? EvidenceStatus.Later : EvidenceStatus.Now;

            if (!IsStateFundedOrFeCollege(establishment.InstitutionTypeNumber ?? 0))
            {
                return(new AmendmentOutcome(OutcomeStatus.AutoReject, "The excluding school must be a recognized maintained school to meet DCSF criteria for 'pupils admitted following permanent exclusion from a maintained school'")
                {
                    ScrutinyStatusCode = ScrutinyCode.ToString(),
                    ReasonId = (int)AmendmentReasonCode.AdmittedFollowingPermanentExclusion,
                    ReasonDescription = ReasonDescription
                });
            }

            if (pupilExclusionDate.Value.ToDateTimeWhenSureNotNull() > amendment.Pupil.AdmissionDate)
            {
                return(new AmendmentOutcome(OutcomeStatus.AutoReject, "The exclusion date is after the date of admission to your school")
                {
                    ScrutinyStatusCode = ScrutinyCode.ToString(),
                    ReasonId = (int)AmendmentReasonCode.AdmittedFollowingPermanentExclusion,
                    ReasonDescription = ReasonDescription
                });
            }

            if (pupilExclusionDate.Value.ToDateTimeWhenSureNotNull() <
                new DateTime(DateTime.Today.AddYears(-2).Year, 8, 01))
            {
                return(new AmendmentOutcome(OutcomeStatus.AutoReject, $"Exclusion Date before 1st September {DateTime.Today.AddYears(-2).Year} - does not meet DCSF criteria for 'pupils admitted following permanent exclusion from a maintained school'")
                {
                    ScrutinyStatusCode = ScrutinyCode.ToString(),
                    ReasonId = (int)AmendmentReasonCode.AdmittedFollowingPermanentExclusion,
                    ReasonDescription = ReasonDescription
                });
            }

            if (!amendment.Pupil.PortlandStudentID.HasValue)
            {
                return(new AmendmentOutcome(OutcomeStatus.AutoReject, "Request to add an unlisted pupil who was admitted following permanent exclusion from a maintained school.  Addition will be reviewed. Please add any missing attainment and send the evidence requested.")
                {
                    ScrutinyStatusCode = ScrutinyCode.ToString(),
                    ReasonId = (int)AmendmentReasonCode.AdmittedFollowingPermanentExclusion,
                    ReasonDescription = ReasonDescription
                });
            }

            return(new AmendmentOutcome(OutcomeStatus.AutoAccept)
            {
                ScrutinyStatusCode = ScrutinyCode.ToString(),
                ReasonId = (int)AmendmentReasonCode.AdmittedFollowingPermanentExclusion,
                ReasonDescription = ReasonDescription
            });
        }
        private Pupil GetPupil(CheckingWindow checkingWindow, PupilDTO pupil, string allocationYear)
        {
            var sen       = _dataService.GetSENStatus().SingleOrDefault(x => x.Code == pupil.SENStatusCode);
            var pincl     = _dataService.GetPINCLs().SingleOrDefault(x => x.Code == pupil.P_INCL);
            var ethnicity = _dataService.GetEthnicities().SingleOrDefault(x => x.Code == pupil.EthnicityCode);
            var language  = _dataService.GetLanguages().SingleOrDefault(x => x.Code == pupil.FirstLanguageCode);
            var school    = _schoolService.GetByDFESNumber(checkingWindow, pupil.DFESNumber);

            var newPupil = new Pupil
            {
                Id            = pupil.id,
                URN           = pupil.URN,
                UPN           = pupil.UPN,
                ULN           = pupil.ULN,
                DfesNumber    = pupil.DFESNumber,
                Forename      = pupil.Forename,
                Surname       = pupil.Surname,
                DOB           = GetDateTime(pupil.DOB),
                Age           = pupil.Age ?? 0,
                Gender        = Gender.FromCode(pupil.Gender),
                AdmissionDate = pupil.ENTRYDAT != null?GetDateTime(pupil.ENTRYDAT.ToString()) : null as DateTime?,
                                    YearGroup = pupil.ActualYearGroup,
                                    Results   = pupil.performance?.Select(p => new Result
                {
                    SubjectCode           = p.SubjectCode,
                    ExamYear              = p.ExamYear,
                    TestMark              = p.TestMark,
                    ScaledScore           = p.ScaledScore,
                    QualificationTypeCode = p.QualificationTypeCode,
                    ExamDate              = GetDateTime(p.Exam_Date),
                    ExamNumber            = p.ExamNumber,
                    FineGrade             = p.FineGrade,
                    GradeCode             = p.GradeCode,
                    MatchReg              = p.MATCHREG,
                    RIncl                = p.R_INCL,
                    SeasonCode           = p.SeasonCode,
                    TierCode             = p.TierCode,
                    AwardingBodyNumber   = p.AwardingBodyNumber,
                    BoardSubjectNumber   = p.BoardSubjectNumber,
                    NationalCentreNumber = p.NationalCentreNumber,
                    QAN              = p.QAN,
                    SubLevelCode     = p.SubLevelCode,
                    PortlandResultID = p.PortlandResultID,
                }).ToList() ?? new List <Result>(Enumerable.Empty <Result>()),
                                    Allocations               = GetSourceOfAllocations(pupil, allocationYear),
                                    LookedAfterEver           = pupil.LookedAfterEver == 1,
                                    School                    = school,
                                    FreeSchoolMealsLast6Years = pupil.FSM6 == 1,
                                    PortlandStudentID         = pupil.PortlandStudentID
            };

            if (sen != null)
            {
                newPupil.SpecialEducationNeed = sen;
            }
            if (ethnicity != null)
            {
                newPupil.Ethnicity = ethnicity;
            }
            if (language != null)
            {
                newPupil.FirstLanguage = language;
            }
            if (ethnicity != null)
            {
                newPupil.Ethnicity = ethnicity;
            }
            if (pincl != null)
            {
                newPupil.PINCL = pincl;
            }

            if (pupil.ForvusIndex != null)
            {
                int.TryParse(pupil.ForvusIndex, out int forvusIndex);
                newPupil.ForvusIndex = forvusIndex;
            }

            return(newPupil);
        }