Hmm... That is a good question.
For building up a GTS I would probably use an SXPR hull with an extension method. First the extension method would add the new component to the GTS:
Code:
public static class GTSExtensions
{
public static void AddExpression(this GTS me, SXCM<TS> component)
{
if (!(me.Hull is SXPR<TS>))
return; // can't do expressions
// Cast hull to express
SXPR<TS> hull = me.Hull as SXPR<TS>;
// Typically new components are intersected, let's do that unless otherwise specified
if (!component.Operator.HasValue)
component.Operator = SetOperator.Intersect;
hull.Add(component);
}
}
Then the main code could just call this extension method:
Code:
GTS frequency = new GTS(new SXPR<TS>());
TS today = new TS(DateTime.Today, DatePrecision.Day);
// Your code
PIVL<TS> Daily = new PIVL<TS>(new IVL<TS>(today), new PQ(1, "d"));
frequency.AddExpression(Daily);
EIVL<TS> atMeals = new EIVL<TS>(DomainTimingEventType.Meal, new IVL<PQ>(new PQ(-1, "h"), new PQ(1, "h")));
frequency.AddExpression(atMeals);
Finally we can check this output by doing some scaffolding:
Code:
// Output for a sample
DatatypeFormatter formatter = new DatatypeFormatter();
using (XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(Console.OpenStandardOutput(), new XmlWriterSettings() { Indent = true })))
{
writer.WriteStartElement("gtsTest", "urn:hl7-org:v3");
formatter.Graph(writer, frequency);
writer.WriteEndElement();
}
Console.ReadKey();
Which results in this:
Code:
<gtsTest xsi:type="SXPR_TS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
" xmlns="urn:hl7-org:v3">
<comp xsi:type="PIVL_TS">
<phase value="20130527" />
<period unit="d" value="1" />
</comp>
<comp xsi:type="EIVL_TS" operator="A">
<event code="C" />
<offset>
<low unit="h" value="-1" />
<high unit="h" value="1" />
</offset>
</comp>
</gtsTest>
Hope that helps!