/// <summary> /// Parses the given text and replaces all ReplacementCodes with the proper value /// </summary> /// <param name="text">The text to parse</param> /// <param name="objectsForParsing">Any objects that are available should be passed on as they may be used as part of the parsing process.</param> /// <returns>The parsed text</returns> public string ParseText(string text, Dictionary <ReplaceableObjectKeys, object> objectsForParsing) { ReplaceableRetriever retriever = new ReplaceableRetriever(this.ahm, objectsForParsing); TextParser <ReplaceableObjectKeys> parser = new TextParser <ReplaceableObjectKeys>(); return(parser.ParseMessage(text, retriever)); }
/// <summary> /// Retrieves the message of the given Message code and replaces all ReplacementCodes with the proper value /// </summary> /// <param name="textDefinitionCode">The code of the text definition to retrieve</param> /// <param name="objectsForParsing">Any objects that are available should be passed on as they may be used as part of the parsing process.</param> /// <returns>The text definition with both it's HTML and Text element parsed</returns> public TextDefinition ParseMessage(string textDefinitionCode, Dictionary <ReplaceableObjectKeys, object> objectsForParsing) { StringBuilder message = new StringBuilder(); TextDefinition td = this.ahm.MessageHandler.GetTextDefinitionByCode(textDefinitionCode); if (td == null) { return(new TextDefinition()); } ReplaceableRetriever retriever = new ReplaceableRetriever(this.ahm, objectsForParsing); TextParser <ReplaceableObjectKeys> parser = new TextParser <ReplaceableObjectKeys>(); string text = parser.ParseMessage(td.Text, retriever); string html = parser.ParseMessage(td.Html, retriever); TextDefinition result = new TextDefinition(); result.DefinitionCode = td.DefinitionCode; result.Text = text; result.Html = html; return(result); }
/// <summary> /// Updates all the text inside the Questionnaire with the proper replacement values. /// Includes, Instructions, TextVersions, DefaultValues, etc. /// </summary> /// <param name="q">The questionnaire to update</param> /// <param name="objectsForParsing">Any objects that are available should be passed on as they may be used as part of the parsing process.</param> public void UpdateQuestionnaireTexts(Questionnaire q, Dictionary <ReplaceableObjectKeys, object> objectsForParsing) { ReplaceableRetriever retriever = new ReplaceableRetriever(this.ahm, objectsForParsing); TextParser <ReplaceableObjectKeys> parser = new TextParser <ReplaceableObjectKeys>(); foreach (QuestionnaireSection section in q.Sections) { foreach (TextVersion v in section.Instructions) { v.Text = parser.ParseMessage(v.Text, retriever); } foreach (QuestionnaireElement element in section.Elements) { foreach (TextVersion v in element.TextVersions) { v.Text = parser.ParseMessage(v.Text, retriever); } if (element.GetType() == typeof(QuestionnaireItem)) { QuestionnaireItem item = (QuestionnaireItem)element; foreach (TextVersion v in item.TextVersions) { v.Text = parser.ParseMessage(v.Text, retriever); } item.SummaryText = parser.ParseMessage(item.SummaryText, retriever); foreach (QuestionnaireItemOptionGroup group in item.OptionGroups) { foreach (TextVersion v in group.TextVersions) { v.Text = parser.ParseMessage(v.Text, retriever); } group.DefaultValue = parser.ParseMessage(group.DefaultValue, retriever); foreach (QuestionnaireItemOption option in group.Options) { option.DefaultValue = parser.ParseMessage(option.DefaultValue, retriever); option.Text = parser.ParseMessage(option.Text, retriever); } } } } } }
/// <summary> /// Runs the notification checker and sends outstanding notifications and reminders /// </summary> public static void SendNotifications() { AccessHandlerManager ahm = new AccessHandlerManager(); List <Notification> notifications = ahm.NotificationHandler.GetNotifications(); Dictionary <string, NotificationData> notificationData = new Dictionary <string, NotificationData>(); foreach (Notification n in notifications) { switch (n.NotificationType) { case NotificationType.RegistrationComplete: Task <User> t = ahm.UserAccessHandler.FindByIdAsync(n.NotificationObjectId); t.Wait(); User user = t.Result; NotifcationManager.AssignNotification(user, n.NotificationType, notificationData); n.NotificationSendTime = DateTime.Now; n.NotificationCompleted = true; ahm.NotificationHandler.UpdateNotification(n); break; case NotificationType.NewQuestionnaire: QuestionnaireUserResponseGroup group = ahm.QuestionnaireAccessHandler.GetSmallQuestionnaireUserResponseGroupById(int.Parse(n.NotificationObjectId)); Patient patient = ahm.UserAccessHandler.FindPatient(group.Patient.Id); if (group != null && !group.Completed && group.Patient.ProxyUserPatientMap.Any(m => m.User.EmailConfirmed) && (n.NotificationSendTime == null || n.NotificationSendTime < DateTime.Now.AddHours(-4))) { NotifcationManager.AssignNotification(patient, n.NotificationType, notificationData); n.NotificationSendTime = DateTime.Now; n.NotificationCompleted = true; ahm.NotificationHandler.UpdateNotification(n); } else { n.NotificationCompleted = true; ahm.NotificationHandler.UpdateNotification(n); } break; } } TextParser parser = new TextParser(ahm); foreach (string email in notificationData.Keys) { NotificationData data = notificationData[email]; StringBuilder textBuilder = new StringBuilder(); StringBuilder htmlBuilder = new StringBuilder(); ReplaceableObjectKeys objectKey = data.NotificationTarget.GetType() == typeof(User) ? ReplaceableObjectKeys.User : ReplaceableObjectKeys.Patient; TextDefinition start = parser.ParseMessage("NotificationStart", new Dictionary <ReplaceableObjectKeys, object>() { { objectKey, data.NotificationTarget } }); TextDefinition end = parser.ParseMessage("NotificationEnd", new Dictionary <ReplaceableObjectKeys, object>() { { objectKey, data.NotificationTarget } }); textBuilder.Append(start.Text); htmlBuilder.Append(start.Html); foreach (NotificationType t in data.Notifications) { TextDefinition td; td = parser.ParseMessage(t.ToString(), new Dictionary <ReplaceableObjectKeys, object>() { { objectKey, data.NotificationTarget } }); textBuilder.Append(td.Text); htmlBuilder.Append(td.Html); /* * switch (t) * { * case NotificationType.RegistrationComplete: * //textBuilder.AppendLine(Text) * td = parser.ParseMessage(NotificationType.RegistrationComplete.ToString(), null); * textBuilder.Append(td.Text); * htmlBuilder.Append(td.Html); * break; * case NotificationType.NewQuestionnaire: * td = parser.ParseMessage(NotificationType.RegistrationComplete.ToString(), null); * textBuilder.Append(td.Text); * htmlBuilder.Append(td.Html); * break; * }*/ } textBuilder.Append(end.Text); htmlBuilder.Append(end.Html); SmtpMailClient.SendMail(email, "Replay Notification", textBuilder.ToString(), htmlBuilder.ToString()); } }