Business Objects

From CaisisWiki

(Difference between revisions)
Jump to: navigation, search
(Creating a New Business Object)
(Creating a New Business Object)
 
(2 intermediate revisions not shown)
Line 3: Line 3:
== Creating a New Business Object ==
== Creating a New Business Object ==
-
Before creating a new Business Object, you should look at the source code for an existing Business Object (preferably one that represents a database table similar to the one for which you are creating a new Business Object) and compare it to the structure of the database table it represents.
+
Before creating a new Business Object, look at the source code for an existing Business Object (preferably one that represents a database table similar to the one for which you are creating a new Business Object) and compare it to the structure of the database table it represents.
 +
 
 +
When initializing a Business Object the initialization methods of the abstract BizObject class (which all Business Object should extend) will treat all public static String members of the Business Object as column names of the table that the Business Object represents. Furthermore, the Attributes associated with the Business Object and its members represent table and field metadata, respectively.
Consider the following snippet of Caisis.BusinessObject.Encounter.cs:
Consider the following snippet of Caisis.BusinessObject.Encounter.cs:
Line 38: Line 40:
         [DataType(typeof(System.String))]
         [DataType(typeof(System.String))]
         public static readonly String EncType = "EncType";
         public static readonly String EncType = "EncType";
 +
       
         ...
         ...
     }
     }
 +
 +
For instance, the Encounters table has a primary key of EncounterId, a parent table and key of Patients and PatientId, respectively, and a many-to-one relationship with the Patients table (i.e. a given patient may have many encounters, but not ''vice-versa''). EncounterId and PatientId are of datatype Int32, and the EncType field is of datatype String. The DataColumns of the DataTable in the Encouter Business Object will have datatypes corresponding to these DataType Attributes.

Current revision as of 14:54, 7 May 2008

Business objects in Caisis represent database tables, allowing clients (e.g. Caisis.UI) to transparently store and retrieve data, and access table metadata.

Creating a New Business Object

Before creating a new Business Object, look at the source code for an existing Business Object (preferably one that represents a database table similar to the one for which you are creating a new Business Object) and compare it to the structure of the database table it represents.

When initializing a Business Object the initialization methods of the abstract BizObject class (which all Business Object should extend) will treat all public static String members of the Business Object as column names of the table that the Business Object represents. Furthermore, the Attributes associated with the Business Object and its members represent table and field metadata, respectively.

Consider the following snippet of Caisis.BusinessObject.Encounter.cs:

   [Tablename("Encounters")]
   [ParentTablename("Patients")]
   [Disease("All")]
   [Exportable]
   [HasSiblings]
   public class Encounter : BizObject
   {
       [NotNull]
       [ParentKey]
       [DataType(typeof(System.Int32))]
       [Deidentify(DeidentifyOptions.Randomize)]
       [LimitIdentification(LimitIdentificationOptions.Randomize)]
       public static readonly String PatientId = "PatientId";
       
       [PrimaryKey]
       [DataType(typeof(System.Int32))]
       public static readonly String EncounterId = "EncounterId";
       
       [DataType(typeof(System.Byte))]
       public static readonly String EncPending = "EncPending";
       
       [DataType(typeof(System.String))]
       [Deidentify(DeidentifyOptions.Omit)]
       public static readonly String EncDateText = "EncDateText";
       
       [DataType(typeof(System.DateTime))]
       [Deidentify(DeidentifyOptions.MaskDate)]
       public static readonly String EncDate = "EncDate";
       
       [DataType(typeof(System.String))]
       public static readonly String EncType = "EncType";
       
       ...
   }

For instance, the Encounters table has a primary key of EncounterId, a parent table and key of Patients and PatientId, respectively, and a many-to-one relationship with the Patients table (i.e. a given patient may have many encounters, but not vice-versa). EncounterId and PatientId are of datatype Int32, and the EncType field is of datatype String. The DataColumns of the DataTable in the Encouter Business Object will have datatypes corresponding to these DataType Attributes.

Personal tools