More GTS Questions: Best "pattern" or approach to build up GTS type.
gboutwell
#1 Posted : Wednesday, May 22, 2013 4:21:56 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/9/2013(UTC)
Posts: 7
Points: 21
Location: Norton, KS

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I'm wondering what the best pattern or approach would be to 'building-up' GTS in 'steps' or portions..

before any loop I declare GTS:

Code:
GTS frequency = new GTS();


Then I have 2 loops in a program in the first loop

I want to add:

Code:
PIVL<TS> Daily = new PIVL<TS>(new IVL<TS>(today), new PQ(1, "d"));
frequency.Hull = Daily;


then on the 2nd loop I would like to merge/add to the existing frequency.Hull:

Code:
EIVL<TS> atMeals = new EIVL<TS>(DomainTimingEventType.Meal, new IVL<PQ>(new PQ(-1, "h"), new PQ(1, "h")));

// psuedo code.
frequency.Hull.Add(atMeals);

// or
frequency = ????.Insect(frequency.Hull, atMeals);


Any thoughts or suggestions on how this could be done...

Thanks...
George
justin.fyfe1
#2 Posted : Monday, May 27, 2013 8:13:01 AM(UTC)

Rank: Administration

Medals: Mobile Tech Grasshopper: Mobile Tech GrasshopperHealth Informatics MVP

Groups: Registered, Administrators
Joined: 7/22/2010(UTC)
Posts: 96
Points: 297
Man
Location: Hamilton, ON

Thanks: 2 times
Was thanked: 17 time(s) in 17 post(s)
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!
1 user thanked justin.fyfe1 for this useful post.
gboutwell on 6/3/2013(UTC)
gboutwell
#3 Posted : Monday, June 3, 2013 10:01:20 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/9/2013(UTC)
Posts: 7
Points: 21
Location: Norton, KS

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Jsutin,

Again, thank you. This is very nice/clean looking code when going to use it. I appreaciate the help and thoughtful suggestions.

George
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

SoClean Theme By Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.098 seconds.