Esempio n. 1
0
        public static (PatchWarningNoteRequest, InfrastructurePerson, Worker, WarningNote) CreatePatchWarningNoteRequest(
            long?warningNoteId                = null,
            DateTime?reviewDate               = null,
            string?reviewedBy                 = null,
            DateTime?nextReviewDate           = null,
            string?startingStatus             = "open",
            string?requestStatus              = "open",
            string?endedBy                    = null,
            string?reviewNotes                = null,
            string?managerName                = null,
            DateTime?discussedWithManagerDate = null,
            bool?disclosedWithIndividual      = null
            )
        {
            var         person      = CreatePerson();
            var         worker      = CreateWorker();
            WarningNote warningNote = CreateWarningNote(person.Id, startingStatus);

            var patchWarningNoteRequest = new Faker <PatchWarningNoteRequest>()
                                          .RuleFor(p => p.WarningNoteId, f => warningNoteId ?? warningNote.Id)
                                          .RuleFor(p => p.ReviewDate, f => reviewDate ?? f.Date.Recent())
                                          .RuleFor(p => p.ReviewedBy, f => reviewedBy ?? worker.Email)
                                          .RuleFor(p => p.NextReviewDate, f => nextReviewDate ?? f.Date.Future())
                                          .RuleFor(p => p.DisclosedWithIndividual, f => disclosedWithIndividual)
                                          .RuleFor(p => p.Status, f => requestStatus)
                                          .RuleFor(p => p.EndedBy, f => endedBy ?? worker.Email)
                                          .RuleFor(p => p.ReviewNotes, f => reviewNotes ?? f.Random.String2(1, 1000))
                                          .RuleFor(p => p.ManagerName, f => managerName ?? f.Random.String2(1, 100))
                                          .RuleFor(p => p.DiscussedWithManagerDate, f => discussedWithManagerDate ?? f.Date.Recent());

            return(patchWarningNoteRequest, person, worker, warningNote);
        }
        public void CanMapWarningNoteFromDatabaseEntityToDomainObject()
        {
            long number = _faker.Random.Number();
            var  dt     = DateTime.Now;
            var  text   = _faker.Random.String();

            var dbWarningNote = new dbWarningNote
            {
                Id        = number,
                PersonId  = number,
                StartDate = dt,
                EndDate   = dt,
                DisclosedWithIndividual = true,
                DisclosedDetails        = text,
                Notes                    = text,
                ReviewDate               = dt,
                NextReviewDate           = dt,
                NoteType                 = text,
                Status                   = text,
                DisclosedDate            = dt,
                DisclosedHow             = text,
                WarningNarrative         = text,
                ManagerName              = text,
                DiscussedWithManagerDate = dt,
                CreatedBy                = text
            };

            var expectedResponse = new WarningNote
            {
                Id        = number,
                PersonId  = number,
                StartDate = dt,
                EndDate   = dt,
                DisclosedWithIndividual = true,
                DisclosedDetails        = text,
                Notes                    = text,
                ReviewDate               = dt,
                NextReviewDate           = dt,
                NoteType                 = text,
                Status                   = text,
                DisclosedDate            = dt,
                DisclosedHow             = text,
                WarningNarrative         = text,
                ManagerName              = text,
                DiscussedWithManagerDate = dt,
                CreatedBy                = text,
                WarningNoteReviews       = new List <WarningNoteReview>()
            };

            var response = dbWarningNote.ToDomain();

            response.Should().BeOfType <WarningNote>();
            response.Should().BeEquivalentTo(expectedResponse);
        }
        public void CanMapPostWarningNoteRequestToDatabaseObject()
        {
            long number = _faker.Random.Number();
            var  dt     = DateTime.Now;
            var  text   = _faker.Random.String();

            var request = new PostWarningNoteRequest
            {
                PersonId  = number,
                StartDate = dt,
                EndDate   = dt,
                DisclosedWithIndividual = true,
                DisclosedDetails        = text,
                Notes                    = text,
                ReviewDate               = dt,
                NextReviewDate           = dt,
                NoteType                 = text,
                DisclosedDate            = dt,
                DisclosedHow             = text,
                WarningNarrative         = text,
                ManagerName              = text,
                DiscussedWithManagerDate = dt,
                CreatedBy                = text
            };

            var expectedResponse = new dbWarningNote
            {
                PersonId  = number,
                StartDate = dt,
                EndDate   = dt,
                DisclosedWithIndividual = true,
                DisclosedDetails        = text,
                Notes                    = text,
                ReviewDate               = dt,
                NextReviewDate           = dt,
                NoteType                 = text,
                Status                   = "open",
                DisclosedDate            = dt,
                DisclosedHow             = text,
                WarningNarrative         = text,
                ManagerName              = text,
                DiscussedWithManagerDate = dt,
                CreatedBy                = text
            };

            var response = request.ToDatabaseEntity();

            response.Should().BeOfType <dbWarningNote>();
            response.Should().BeEquivalentTo(expectedResponse);
        }
 public static WarningNote ToDomain(this dbWarningNote dbWarningNote, List <WarningNoteReview>?reviews = null)
 {
     return(new WarningNote
     {
         Id = dbWarningNote.Id,
         PersonId = dbWarningNote.PersonId,
         StartDate = dbWarningNote.StartDate,
         EndDate = dbWarningNote.EndDate,
         DisclosedWithIndividual = dbWarningNote.DisclosedWithIndividual,
         DisclosedDetails = dbWarningNote.DisclosedDetails,
         Notes = dbWarningNote.Notes,
         ReviewDate = dbWarningNote.ReviewDate,
         NextReviewDate = dbWarningNote.NextReviewDate,
         NoteType = dbWarningNote.NoteType,
         Status = dbWarningNote.Status,
         DisclosedDate = dbWarningNote.DisclosedDate,
         DisclosedHow = dbWarningNote.DisclosedHow,
         WarningNarrative = dbWarningNote.WarningNarrative,
         ManagerName = dbWarningNote.ManagerName,
         DiscussedWithManagerDate = dbWarningNote.DiscussedWithManagerDate,
         CreatedBy = dbWarningNote.CreatedBy,
         WarningNoteReviews = reviews ?? new List <WarningNoteReview>()
     });
 }
Esempio n. 5
0
        public void PatchWarningNote(PatchWarningNoteRequest request)
        {
            WarningNote warningNote = _databaseContext.WarningNotes.FirstOrDefault(x => x.Id == request.WarningNoteId);

            if (warningNote == null)
            {
                throw new PatchWarningNoteException($"Warning Note with given id ({request.WarningNoteId}) not found");
            }

            if (warningNote.Status == "closed")
            {
                throw new PatchWarningNoteException(
                          $"Warning Note with given id ({request.WarningNoteId}) has already been closed");
            }

            Person person = _databaseContext.Persons.FirstOrDefault(x => x.Id == warningNote.PersonId);

            if (person == null)
            {
                throw new PatchWarningNoteException("Person not found");
            }

            Worker worker = _databaseContext.Workers.FirstOrDefault(x => x.Email == request.ReviewedBy);

            if (worker == null)
            {
                throw new PatchWarningNoteException($"Worker ({request.ReviewedBy}) not found");
            }


            warningNote.LastReviewDate = request.ReviewDate;
            warningNote.NextReviewDate = request.NextReviewDate;
            if (request.Status?.ToLower() == "closed")
            {
                warningNote.Status         = "closed";
                warningNote.EndDate        = _systemTime.Now;
                warningNote.NextReviewDate = null;
            }

            warningNote.LastModifiedBy = request.ReviewedBy;

            var review = PostWarningNoteReview(request);

            _databaseContext.WarningNoteReview.Add(review);
            _databaseContext.SaveChanges();

            var dt = DateTime.Now;

            var note = new WarningNoteCaseNote
            {
                FirstName       = person.FirstName,
                LastName        = person.LastName,
                MosaicId        = person.Id.ToString(),
                Timestamp       = dt.ToString("dd/MM/yyyy H:mm:ss"),
                Note            = $"{dt.ToShortDateString()} | Warning Note | {((request.Status == "closed") ? "Warning note against this person ended" : "Warning note against this person reviewed")}",
                FormNameOverall = "API_WarningNote",
                FormName        = (request.Status == "closed") ? "Warning Note Ended" : "Warning Note Reviewed",
                WarningNoteId   = warningNote.Id.ToString(),
                WorkerEmail     = request.ReviewedBy
            };

            var caseNotesDocument = new CaseNotesDocument
            {
                CaseFormData = JsonConvert.SerializeObject(note)
            };

            _ = _processDataGateway.InsertCaseNoteDocument(caseNotesDocument).Result;
        }