Thursday, December 8, 2011

Collection Shortcuts in Everest 1.0


The goal of the Everest framework data types is to provide functionality that allows developers to easily construct and interact with the HL7v3 data types. In previous versions of the Everest Framework, creating collections could be difficult. Consider the AD data type which is nothing more than a collection of ADXP components. In previous versions of Everest, creating this structure would look something like this:

AD homeAddress = new AD(
  new SET<CS<PostalAddressUse>>()
  {
     PostalAddressUse.Alphabetic,
     PostalAddressUse.Direct
  },
  new ADXP[] {
     new ADXP("123 Main Street", AddressPartType.StreetAddressLine),
     new ADXP("West", AddressPartType.Direction),
     new ADXP("Hamilton", AddressPartType.City),
     new ADXP("Ontario", AddressPartType.State),
     new ADXP("Canada", AddressPartType.Country)
  }
);

This code can be quite large and is difficult to track if not styled properly (indentation is the key here). So, to make the construction of sets a little easier, we've added static "creator" methods on each of the collection data types. They are used as follows:

AD homeAddress = AD.CreateAD(
   SET<PostalAddressUse>.CreateSET(
      PostalAddressUse.Alphabetic,
      PostalAddressUse.Direct
   ),
   new ADXP("123 Main Street", AddressPartType.City),
   new ADXP("West", AddressPartType.Direction),
   new ADXP("Hamilton", AddressPartType.City),
   new ADXP("Ontario", AddressPartType.State),
   new ADXP("Canada", AddressPartType.Country)
);

The benefit of this shortcut is illustrated better with more complex sets such as SXPR and QSET. The following snippet represents the construction of an SXPR that represents numbers {1..10}, intersected with the result of a union of numbers {3..5} and {7..9}.

SXPR<INT> result = new SXPR<INT>()
{
   new IVL<INT>(1, 10),
   new SXPR<INT>() {
       Operator = SetOperator.Intersect,
       Terms = new LIST<SXCM<INT>>() {
          new IVL<INT>(3, 5),
          new IVL<INT>(7, 9)
          {
              Operator = SetOperator.Inclusive
          }
       }
   }
};

Using the new constructor which is a shortcut, the following expression can be used:

SXPR<INT> result = new SXPR<INT>(
   new IVL<INT>(1, 10),
   new SXPR<INT>(
       new IVL<INT>(3, 5),
       new IVL<INT>(7, 9)
       {
           Operator = SetOperator.Inclusive
       }
   )
   {
      Operator = SetOperator.Intersect
   }
);

These new shortcut methods are intended to assist developers even more than previous attempts at the Data Types implementation and are one of the many improvements in the Everest 1.0 data types library.

No comments:

Post a Comment