public ParticipantJourneyModality RetrieveParticipantJourneyModality(ParticipantJourneySearchViewModel psm, int formID, int modalityID, out string message) { message = string.Empty; ParticipantJourneyModality result = null; if (psm == null) { message = "Parameter cannot be null"; } else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0) { message = "Please enter valid NRIC and select Live Event"; } else { using (var unitOfWork = CreateUnitOfWork()) { result = unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModality(psm.Nric, psm.PHSEventId, formID, modalityID); } } return(result); }
public void RetrieveParticipantJourneyModality_NoRecordFound() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; int formId = 1; string message = string.Empty; ParticipantJourneyModality result = _target.RetrieveParticipantJourneyModality(psm, formId, 1, out message); Assert.IsNull(result); }
public TemplateViewModel FindTemplateToDisplay(ParticipantJourneySearchViewModel psm, int formID, int selectedModalityId, bool embed, TemplateFieldMode fieldMode, out string message) { TemplateViewModel model = null; using (var unitOfWork = CreateUnitOfWork()) { ParticipantJourneyModality participantJourneyModality = RetrieveParticipantJourneyModality(psm, formID, selectedModalityId, out message); if (participantJourneyModality != null) { var template = participantJourneyModality.TemplateID.HasValue ? unitOfWork.FormRepository.GetTemplate(participantJourneyModality.TemplateID.Value) : FindLatestTemplate(formID, unitOfWork); if (template != null) { model = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT); model.Embed = embed; bool valueRequiredForRegistration = false; if (Internal_Form_Type_Registration.Equals(model.InternalFormType)) { if (participantJourneyModality.EntryId == Guid.Empty) { valueRequiredForRegistration = true; } } foreach (var field in model.Fields) { field.Mode = fieldMode; field.ParticipantNric = psm.Nric; field.IsValueRequiredForRegistration = valueRequiredForRegistration; field.EntryId = participantJourneyModality.EntryId.ToString(); } } } else { throw new Exception("No participantJourneyModality found"); } return(model); } }
protected override void HandleTemplateFieldValue(TemplateFieldViewModel field, string value, Guid entryId) { ParticipantJourneyModality participantJourneyModality = FindParticipantJourneyModality(); if (participantJourneyModality != null) { if (participantJourneyModality.EntryId == Guid.Empty) { field.CreatedDateTime = DateTime.Now; field.CreatedBy = GetLoginUserName(); UnitOfWork.FormRepository.InsertTemplateFieldValue(field, value, entryId); } else { Guid existingEntryId = participantJourneyModality.EntryId; TemplateFieldValue fieldValue = UnitOfWork.FormRepository.GetTemplateFieldValue(field, existingEntryId); if (fieldValue != null) { field.UpdatedDateTime = DateTime.Now; field.UpdatedBy = GetLoginUserName(); UnitOfWork.FormRepository.UpdateTemplateFieldValue(fieldValue, field, value); } else { field.CreatedDateTime = DateTime.Now; field.CreatedBy = GetLoginUserName(); UnitOfWork.FormRepository.InsertTemplateFieldValue(field, value, existingEntryId); } } } else { throw new Exception("No participantJourneyModality found"); } }
public void CreateFormEntriesDataTableTest_SimpleFormWithParticipantJourney() { Template template; TemplateViewModel templateViewModel; FormViewModel formViewModel = new FormViewModel(); CreateTemplateAndField(formViewModel, Constants.TemplateFieldType.TEXTBOX, "Textbox 12345", out template, out templateViewModel); templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID); Assert.IsNotNull(templateViewModel.Fields); Assert.AreEqual(1, templateViewModel.Fields.Count); templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList(); Assert.AreEqual(0, templateViewModel.Entries.Count); FormCollection submissionCollection = new FormCollection(); submissionCollection.Add("SubmitFields[1].TextBox", "Very important"); IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>(); submissionFields.Add("1", "1"); string fillinResult = _formAccessManager.FillIn(submissionFields, templateViewModel, submissionCollection); Assert.AreEqual(fillinResult, "success"); templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList(); Assert.AreEqual(1, templateViewModel.Entries.Count); var entryId = templateViewModel.Entries.FirstOrDefault().EntryId; Assert.AreNotEqual(Guid.Empty, entryId); PHSEvent phsEvent = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(199), IsActive = false }; Modality modality = new Modality() { Name = "Test Modality" }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = new DateTime(1988, 11, 22), Gender = "Male", FullName = "Tester 123" }; _unitOfWork.Participants.Add(participant); _unitOfWork.Events.Add(phsEvent); participant.PHSEvents.Add(phsEvent); _unitOfWork.Participants.Add(participant); phsEvent.Modalities.Add(modality); _unitOfWork.Complete(); ParticipantJourneyModality journeyModality = new ParticipantJourneyModality() { ParticipantID = 1, PHSEventID = 1, ModalityID = 1, FormID = 1, TemplateID = 1, EntryId = new Guid(entryId) }; _unitOfWork.ParticipantJourneyModalities.Add(journeyModality); _unitOfWork.Complete(); FormExportViewModel model = new FormExportViewModel() { FormID = 1 }; var result = _target.CreateFormEntriesDataTable(model).ValuesDataTable; Assert.IsNotNull(result); Assert.AreEqual(3, result.Columns.Count); Assert.AreEqual("Nric", result.Columns[0].ColumnName); Assert.AreEqual("Textbox 12345", result.Columns[1].ColumnName); Assert.AreEqual(1, result.Rows.Count); Assert.AreEqual("S8250369B", result.Rows[0]["Nric"]); Assert.AreEqual("Very important", result.Rows[0]["Textbox 12345"]); }
protected override void HandleAdditionalInsert(TemplateViewModel templateView, Template template, FormCollection formCollection, Guid entryId, IDictionary <int, string> submissionFields) { IDictionary <string, object> values = new Dictionary <string, object>(); foreach (var field in templateView.Fields) { var value = field.SubmittedValue(formCollection); if (!string.IsNullOrEmpty(field.RegistrationFieldName)) { values.Add(field.RegistrationFieldName, value); } } if (Internal_Form_Type_Registration.Equals(template.Form.InternalFormType)) { //update participant Participant participant = UnitOfWork.Participants.FindParticipant(psm.Nric, psm.PHSEventId); if (participant != null) { participant.FullName = getStringValue(values, Registration_Field_Name_FullName); participant.HomeNumber = getStringValue(values, Registration_Field_Name_HomeNumber); participant.MobileNumber = getStringValue(values, Registration_Field_Name_MobileNumber); participant.DateOfBirth = getDateTimeValue(values, Registration_Field_Name_DateOfBirth); participant.Language = getStringValue(values, Registration_Field_Name_Language); participant.Gender = getStringValue(values, Registration_Field_Name_Gender); participant.Citizenship = getStringValue(values, Registration_Field_Name_Citizenship); participant.Race = getStringValue(values, Registration_Field_Name_Race); participant.Salutation = getStringValue(values, Registration_Field_Name_Salutation); string addressValue = getStringValue(values, Registration_Field_Name_Address); if (!string.IsNullOrEmpty(addressValue)) { AddressViewModel address = addressValue.FromJson <AddressViewModel>(); participant.Address = address.ConvertToOneLineAddress(); participant.PostalCode = address.ZipCode; } else { participant.Address = ""; participant.PostalCode = ""; } } } ParticipantJourneyModality participantJourneyModality = FindParticipantJourneyModality(); if (participantJourneyModality != null) { if (participantJourneyModality.EntryId == Guid.Empty) { UnitOfWork.ParticipantJourneyModalities.UpdateParticipantJourneyModality(participantJourneyModality, templateView.TemplateID.Value, entryId); } } else { throw new Exception("No participantJourneyModality found"); } foreach (var field in templateView.Fields) { if (field.ConditionTemplateFieldID.HasValue) { if (!isConditionalFieldRequired(field, submissionFields)) { continue; } } if (field.SummaryFieldName != null && field.SummaryFieldName.Length > 0 && field.SummaryType != null && field.SummaryType.Length > 0) { Summary summary = null; summary = UnitOfWork.Summaries.FindSummary(participantJourneyModality.PHSEventID, participantJourneyModality.ParticipantID, participantJourneyModality.ModalityID, (int)field.TemplateFieldID); if (summary == null) { summary = new Summary(); summary.Label = field.SummaryFieldName; summary.ModalityID = participantJourneyModality.ModalityID; summary.ParticipantID = participantJourneyModality.ParticipantID; summary.PHSEventID = participantJourneyModality.PHSEventID; summary.SummaryType = field.SummaryType; summary.SummaryLabel = field.Label; summary.SummaryValue = field.InputValue; summary.TemplateFieldID = (int)field.TemplateFieldID; summary.StandardReferenceID = field.StandardReferenceID; UnitOfWork.Summaries.Add(summary); } else { summary.Label = field.SummaryFieldName; summary.SummaryType = field.SummaryType; summary.SummaryLabel = field.Label; summary.SummaryValue = field.InputValue; summary.StandardReferenceID = field.StandardReferenceID; } } } }
public void FindTemplateToDisplay_OlderVersionAfterSubmitBefore() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; int formId = 1; PHSEvent phsEvent = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(-199), IsActive = false }; Participant participant = new Participant() { Nric = "S8250369B" }; Modality modality = new Modality() { Name = "Test Modality" }; Form form = new Form { IsActive = true, Title = "Test form" }; Template templateOne = new Template() { Status = Constants.TemplateStatus.DRAFT.ToString(), IsActive = true, Version = 1, DateAdded = DateTime.Now }; Template templateTwo = new Template() { Status = Constants.TemplateStatus.DRAFT.ToString(), IsActive = true, Version = 2, DateAdded = DateTime.Now }; _unitOfWork.Events.Add(phsEvent); participant.PHSEvents.Add(phsEvent); _unitOfWork.Participants.Add(participant); form.Templates.Add(templateOne); form.Templates.Add(templateTwo); modality.Forms.Add(form); phsEvent.Modalities.Add(modality); _unitOfWork.Complete(); ParticipantJourneyModality journeyModality = new ParticipantJourneyModality() { ParticipantID = 1, PHSEventID = psm.PHSEventId, ModalityID = 1, FormID = formId, TemplateID = 1 }; _unitOfWork.ParticipantJourneyModalities.Add(journeyModality); _unitOfWork.Complete(); string message = string.Empty; var result = _target.FindTemplateToDisplay(psm, formId, 1, false, TemplateFieldMode.INPUT, out message); Assert.IsNotNull(result); var templateResult = _target.FindTemplate(result.TemplateID.Value); Assert.IsNotNull(templateResult); Assert.AreEqual(1, templateResult.Version); }
public void RetrieveParticipantJourneyModality_ShouldHaveRecord() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; int formId = 1; Guid entryId = new Guid(); PHSEvent phsEvent = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(-199), IsActive = false }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = DateTime.Now, HomeNumber = "88776655" }; Modality modality = new Modality() { Name = "Test Modality" }; Form form = new Form { Title = "Test form" }; _unitOfWork.Events.Add(phsEvent); participant.PHSEvents.Add(phsEvent); _unitOfWork.Participants.Add(participant); modality.Forms.Add(form); phsEvent.Modalities.Add(modality); ParticipantJourneyModality journeyModality = new ParticipantJourneyModality() { ParticipantID = 1, PHSEventID = psm.PHSEventId, ModalityID = 1, FormID = formId, EntryId = entryId }; _unitOfWork.ParticipantJourneyModalities.Add(journeyModality); _unitOfWork.Complete(); string message = string.Empty; ParticipantJourneyModality result = _target.RetrieveParticipantJourneyModality(psm, formId, 1, out message); Assert.IsNotNull(result); Assert.AreEqual(entryId, result.EntryId); }
public void InternalFillIn_UpdateValues() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; TemplateViewModel templateViewModel = CreateFormAndTemplateWithSampleField(); PHSEvent phsEvent = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(-199), IsActive = false }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = DateTime.Now, HomeNumber = "88776655" }; Modality modality = new Modality() { Name = "Test Modality" }; Form form = new Form { Title = "Test form" }; _unitOfWork.Events.Add(phsEvent); participant.PHSEvents.Add(phsEvent); _unitOfWork.Participants.Add(participant); modality.Forms.Add(form); phsEvent.Modalities.Add(modality); ParticipantJourneyModality journeyModality = new ParticipantJourneyModality() { ParticipantID = 1, PHSEventID = psm.PHSEventId, ModalityID = 1, FormID = 1 }; _unitOfWork.ParticipantJourneyModalities.Add(journeyModality); _unitOfWork.Complete(); FormCollection submissionCollection = new FormCollection(); submissionCollection.Add("SubmitFields[1].TextBox", "HelloTest"); IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>(); submissionFields.Add("1", "1"); _target.InternalFillIn(psm, 1, submissionFields, templateViewModel, submissionCollection); submissionCollection = new FormCollection(); submissionCollection.Add("SubmitFields[1].TextBox", "Hello Test 2"); string result = _target.InternalFillIn(psm, 1, submissionFields, templateViewModel, submissionCollection); Assert.AreEqual(result, "success"); templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList(); Assert.AreEqual(1, templateViewModel.Entries.Count); Assert.AreEqual("Hello Test 2", templateViewModel.Entries.FirstOrDefault().Value); ParticipantJourneyModality journeyModalityResult = _unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModality("S8250369B", 1, 1, 1); Assert.IsNotNull(journeyModalityResult); Assert.AreEqual(templateViewModel.Entries.FirstOrDefault().EntryId, journeyModalityResult.EntryId.ToString()); }
public string UpdateParticipantJourneyModalityFromMSS(ICollection <ParticipantJourneyModalityCircleViewModel> newPtJourneyModalityItems) { using (var unitOfWork = CreateUnitOfWork()) { Participant participant = unitOfWork.Participants.FindParticipant(newPtJourneyModalityItems.First().Nric); PHSEvent phsEvent = unitOfWork.Events.GetEvent(int.Parse(newPtJourneyModalityItems.First().EventId)); IEnumerable <ParticipantJourneyModality> oldPJMItems = unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModalityByParticipantEvent(newPtJourneyModalityItems.First().Nric, int.Parse(newPtJourneyModalityItems.First().EventId)); foreach (ParticipantJourneyModalityCircleViewModel newModalities in newPtJourneyModalityItems) { Boolean oldModalityExists = false; int oldPJMId = 0; foreach (ParticipantJourneyModality oldModalities in oldPJMItems) { if (newModalities.ModalityID == oldModalities.ModalityID) { oldModalityExists = true; oldPJMId = oldModalities.ParticipantJourneyModalityID; } } // to create new participantjourneymodality if (newModalities.IsActive && !oldModalityExists) { Modality modality = unitOfWork.Modalities.Get(newModalities.ModalityID); foreach (Form form in modality.Forms) { ParticipantJourneyModality newPJM = new ParticipantJourneyModality(); newPJM.Participant = participant; newPJM.PHSEvent = phsEvent; newPJM.Modality = unitOfWork.Modalities.Get(newModalities.ModalityID); newPJM.Form = form; if (!Constants.IsFormForSubmit(form.FormID)) { newPJM.TemplateID = unitOfWork.FormRepository.GetForm(form.FormID).Templates.FirstOrDefault().TemplateID; newPJM.EntryId = new Guid("10000000-9999-9999-9999-000000000001"); } unitOfWork.ParticipantJourneyModalities.Add(newPJM); } using (TransactionScope scope = new TransactionScope()) { unitOfWork.Complete(); scope.Complete(); } } // to delete old participantjourneymodality // todo: before delete, to check if there is exsiting form submission if (!newModalities.IsActive && oldModalityExists) { Modality modality = unitOfWork.Modalities.Get(newModalities.ModalityID); foreach (Form form in modality.Forms) { ParticipantJourneyModality toRemovePJM = unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModality(participant.Nric, phsEvent.PHSEventID, form.FormID, modality.ModalityID); if (toRemovePJM.TemplateID != null && toRemovePJM.EntryId != new Guid("10000000-9999-9999-9999-000000000001")) { return("Failed"); } else { unitOfWork.ParticipantJourneyModalities.Remove(toRemovePJM); } using (TransactionScope scope = new TransactionScope()) { unitOfWork.Complete(); scope.Complete(); } } } } return("Updated Successfully"); } }
public string RegisterParticipant(ParticipantJourneySearchViewModel psm) { string result = null; if (psm == null) { return("Parameter cannot be null"); } else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0) { return("Please enter valid NRIC and select Live Event"); } else if (!NricChecker.IsNRICValid(psm.Nric)) { return("Invalid Nric"); } else { using (var unitOfWork = CreateUnitOfWork()) { PHSEvent phsEvent = unitOfWork.Events.GetEventWithModalityForm(psm.PHSEventId); if (phsEvent == null) { return("Screening Event is not active"); } else { Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric); if (participant != null) { if (participant.PHSEvents.All(e => e.PHSEventID == psm.PHSEventId)) { return("Invalid register participant"); } } PreRegistration preRegistration = unitOfWork.PreRegistrations.FindPreRegistration(p => p.Nric.Equals(psm.Nric)); using (TransactionScope scope = new TransactionScope()) { if (participant == null) { participant = new Participant() { Nric = psm.Nric }; copyPreRegistrationToParticipant(participant, preRegistration); unitOfWork.Participants.AddParticipantWithPHSEvent(participant, phsEvent); } else { copyPreRegistrationToParticipant(participant, preRegistration); unitOfWork.Participants.AddPHSEventToParticipant(participant, phsEvent); } foreach (var modality in phsEvent.Modalities) { if (modality.IsMandatory) { foreach (var form in modality.Forms) { ParticipantJourneyModality participantJourneyModality = new ParticipantJourneyModality() { ParticipantID = participant.ParticipantID, PHSEventID = phsEvent.PHSEventID, FormID = form.FormID, ModalityID = modality.ModalityID }; if (!Constants.IsFormForSubmit(form.FormID)) { participantJourneyModality.TemplateID = form.Templates.FirstOrDefault().TemplateID; participantJourneyModality.EntryId = new Guid("10000000-9999-9999-9999-000000000001"); } participant.ParticipantJourneyModalities.Add(participantJourneyModality); } } } unitOfWork.Complete(); scope.Complete(); result = "success"; } } } } return(result); }