Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Last active December 14, 2015 07:39
Show Gist options
  • Select an option

  • Save jmarnold/5052180 to your computer and use it in GitHub Desktop.

Select an option

Save jmarnold/5052180 to your computer and use it in GitHub Desktop.
public class CaseSnapshotFlattener : ICaseSnapshotFlattener
{
private readonly IProjectionRunner _runner;
public CaseSnapshotFlattener(IProjectionRunner runner)
{
_runner = runner;
}
public IDictionary<string, object> ToJson(CaseSnapshot model)
{
var node = new DictionaryMediaNode();
_runner.Run(new CaseSnapshotProjection(), model, node);
return node.Values;
}
}
public class CaseSnapshotProjection : Projection<CaseSnapshot>
{
public CaseSnapshotProjection()
: base(DisplayFormatting.UseDisplayFormatting)
{
Value(x => x.Id);
Value(x => x.ScheduledTime);
Value(x => x.IsAddOn).FormattedBy(listValue => listValue.Value == AddOnList.Yes);
Value(x => x.Cancelled).FormattedBy(x => x.IsTrue);
ForAttribute("Title").Use(context =>
{
var lookup = context.Service<UserLookup>();
var lastName = lookup.PersonFor(context.Subject.Surgeon1.Value).LastName;
return "{0}, {1}".ToFormat(lastName, context.Subject.ScheduledTime.Value.ToString("hhmm"));
});
ForAttribute("ShortTitle").Use(context => "{0}, {1}".ToFormat(
context.Subject.ScheduledTime.Value.ToString("hhmm"),
context.Subject.CaseCode));
Value(x => x.Id).Name("url").WriteUrlFor(guid => new ViewCaseSnapshot{
Id = guid
});
Value(x => x.Id).Name("mobileUrl").WriteUrlFor(id => new MobileViewCaseSnapshot{
Id = id
});
ForAttribute("Timestamps").Use(context => TimestampJson.ToJson(context.Subject.Data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment