public void CreateMacro_UsingUnknownMarkups_ExceptionIsThrown() { var macro = "Hello $unknown$ $LASTNAME$"; var patient = new Patient() { FirstName = "ROBERT", LastName = "DUPONT" }; var builder = new MacroBuilder(patient); Assert.Throws<InvalidMacroException>(() => builder.Resolve(macro)); }
public void CreateMacro_UsingUpperCaseMarkups_MarkupsReplacesWithValues() { var robert = "Robert"; var dupont = "Dupont"; var macro = "Hello $FIRSTNAME$ $LASTNAME$"; var expected = "Hello " + robert + " " + dupont; var patient = new Patient() { FirstName = robert, LastName = dupont }; var builder = new MacroBuilder(patient); var result = builder.Resolve(macro); Assert.AreEqual(expected, result); }
public void CreateMacro_ReplaceFullName_MarkupsReplacedWithValue() { var robert = "Robert"; var dupont = "Dupont"; var macro = "Hello $firstname$ $lastname$"; var expected = "Hello " + robert + " " + dupont; var patient = new Patient() { FirstName = robert, LastName = dupont }; var builder = new MacroBuilder(patient); var result = builder.Resolve(macro); Assert.AreEqual(expected, result); }
public string Resolve(string macro) { macro = this.Standardise(macro); if (MacroBuilder.IsValidExpression(macro)) { macro = macro.Replace(Markups.FirstName, patient.FirstName); macro = macro.Replace(Markups.LastName, patient.LastName); macro = macro.Replace(Markups.Birthdate, patient.BirthDate.ToShortDateString()); macro = macro.Replace(Markups.Height, patient.Height.ToString()); macro = macro.Replace(Markups.Now, DateTime.Now.ToString("HH:mm")); macro = macro.Replace(Markups.Today, DateTime.Today.ToShortDateString()); macro = macro.Replace(Markups.Age, this.GetAge(patient)); return(macro); } else { throw new InvalidMacroException(); } }
/// <summary> /// Resolves the specified macro with the data of the specified patient. /// </summary> /// <param name="macro">The macro.</param> /// <param name="patient">The patient.</param> /// <returns></returns> public string Resolve(MacroDto macro, LightPatientDto patient) { if (macro == null || patient == null) return string.Empty; var p = this.Session.Get<Patient>(patient.Id); if (p == null) throw new EntityNotFoundException(typeof(Patient)); var builder = new MacroBuilder(p); return builder.Resolve(macro.Expression); }