public static CareCaseData ToCareCaseData(this CaseSubmission caseSubmission, ListCasesRequest listCasesRequest) { var resident = listCasesRequest.MosaicId != null?caseSubmission.Residents .First(x => x.Id == long.Parse(listCasesRequest.MosaicId)) : caseSubmission.Residents[0]; return(new CareCaseData { RecordId = caseSubmission.SubmissionId.ToString(), PersonId = resident.Id, FirstName = resident.FirstName, LastName = resident.LastName, OfficerEmail = caseSubmission.Workers[0].Email, CaseFormTimestamp = caseSubmission.SubmittedAt?.ToString("yyyy-MM-dd") ?? DateTime.Now.ToString("yyyy-MM-dd"), FormName = caseSubmission.FormId, DateOfBirth = resident.DateOfBirth?.ToString("dd/MM/yyyy"), DateOfEvent = caseSubmission.DateOfEvent?.ToString("O") ?? caseSubmission.CreatedAt.ToString("O"), CaseFormUrl = caseSubmission.SubmissionId.ToString(), FormType = "flexible-form", Title = caseSubmission.Title, Deleted = (bool)(caseSubmission.Deleted == null ? false : caseSubmission.Deleted), DeletionDetails = listCasesRequest.IncludeDeletedRecords ? caseSubmission.DeletionDetails : null }); }
public static Domain.CaseSubmission ToDomain(this CaseSubmission caseSubmission, bool includeFormAnswers = true, bool includeEditHistory = true, bool pruneUnfinished = false, bool includeDeletionDetails = true) { var mapSubmissionStateToString = new Dictionary <SubmissionState, string> { { SubmissionState.InProgress, "In progress" }, { SubmissionState.Submitted, "Submitted" }, { SubmissionState.Approved, "Approved" }, { SubmissionState.Discarded, "Discarded" }, { SubmissionState.PanelApproved, "Panel Approved" } }; if (pruneUnfinished) { return(new Domain.CaseSubmission { SubmissionId = caseSubmission.SubmissionId.ToString(), FormId = caseSubmission.FormId, CreatedBy = new Worker { Email = caseSubmission.CreatedBy.Email, }, CreatedAt = caseSubmission.CreatedAt, Residents = caseSubmission.Residents.Select(r => new Person { Id = r.Id, AgeContext = r.AgeContext, FirstName = r.FirstName, LastName = r.LastName, Restricted = r.Restricted }).ToList(), Workers = caseSubmission.Workers.Select(w => new Worker { Email = w.Email }).ToList(), SubmissionState = mapSubmissionStateToString[caseSubmission.SubmissionState], LastEdited = caseSubmission.EditHistory.Last().EditTime, CompletedSteps = caseSubmission.FormAnswers.Count, Title = caseSubmission.Title, Deleted = caseSubmission.Deleted ?? false, DeletionDetails = includeDeletionDetails ? caseSubmission.DeletionDetails : null }); } return(new Domain.CaseSubmission { SubmissionId = caseSubmission.SubmissionId.ToString(), FormId = caseSubmission.FormId, Residents = caseSubmission.Residents, Workers = caseSubmission.Workers.Select(w => w.ToDomain(false)).ToList(), CreatedAt = caseSubmission.CreatedAt, DateOfEvent = caseSubmission.DateOfEvent, CreatedBy = caseSubmission.CreatedBy.ToDomain(false), SubmittedAt = caseSubmission.SubmittedAt, SubmittedBy = caseSubmission.SubmittedBy?.ToDomain(false), ApprovedAt = caseSubmission.ApprovedAt, ApprovedBy = caseSubmission.ApprovedBy?.ToDomain(false), PanelApprovedAt = caseSubmission.PanelApprovedAt, PanelApprovedBy = caseSubmission.PanelApprovedBy?.ToDomain(false), RejectionReason = caseSubmission.RejectionReason, EditHistory = includeEditHistory ? caseSubmission.EditHistory.Select(e => new EditHistory <Worker> { EditTime = e.EditTime, Worker = e.Worker.ToDomain(false) }).ToList() : null, SubmissionState = mapSubmissionStateToString[caseSubmission.SubmissionState], FormAnswers = includeFormAnswers ? caseSubmission.FormAnswers : null, Title = caseSubmission.Title, LastEdited = caseSubmission.EditHistory.Last().EditTime, CompletedSteps = caseSubmission.FormAnswers.Count, Deleted = caseSubmission.Deleted ?? false, DeletionDetails = includeDeletionDetails ? caseSubmission.DeletionDetails : null }); }