Schedule.NET
ActiveX
General
Site



DOWNLOADS | eSTORE | CONTACT | MESSAGE BOARD

Schedule.NET Searching


One of the most useful things about the defined lists is their ability to return objects from their complementary collections based on querying information. The AppointmentCollection has an overloaded Find method that returns a subset of appointments based on some search criteria. The CategoryCollection and ProviderCollection classes have only basic functionality as they can only search by text. Both of these object types are really nothing more than a piece of text and a color, so there is really nothing much on which to search. The real search functionality is built into the AppointmentCollection. Each appointment has many properties and as such you will want to find objects by different criteria.

Let us look at a real-world example. In a doctor’s office you may wish to find all appointments in a date range. The following code snippet will returns a list of appointments between January 1, 2004 and January 5, 2004, inclusive.
 
Dim list1 As Gravitybox.Objects.AppointmentListlist1 = _ Schedule1.AppointmentCollection.Find(#1/1/2004#, #1/5/2004#)


This is useful if you wish to provide functionality to a user to query appointments by date. You could retrieve a date range from the user in a custom dialog and then, after querying the AppointmentCollection, display the results on screen in a listview control perhaps. This ensures that you do not have to go re-query your database for information that you have already have.

This functionality is useful in and of itself; however in the real world you will most likely need to construct much more complicated queries. Following the example above, image that you wish to find all appointment in that date range for "John Doe". Let’s assume that a patient’s name is displayed in appointment’s Subject property. Now following the example above we search by Subject. This new list consists of all the appointments for John Doe.

Dim list2 As Gravitybox.Objects.AppointmentListList2 = _
Schedule1.AppointmentCollection.Find("John Doe")


Now comes the interesting part. These are the three operations defined on lists: Union, Intersection, and Subtraction. You can use these list operations to define arbitrarily complex queries. 

Following the two examples above, we can now build a list that contains all items in list1 and also all items in list2. This is a set operation known as Intersection. Essentially finding all appointments for John Doe between the dates of January 1, 2004 and January 5, 2004.

Dim list3 As Gravitybox.Objects.AppointmentListlist3 = _
list1.Intersect(list2)


The new "list3" variable will hold the intersection of the two lists, meaning appointments that are in both lists, with no duplicates. If you wanted to find all appointments for that date range (for any patient) or any appointments for "John Doe", you would use the "Union" method. This would basically concatenate both lists into one. If you wanted all appointments in the date range except for "John Doe" appointments then you would use the "Subtract" method to remove any appointments in list2 from list1.

Keep in mind when building lists that the Find method will never return duplicate objects in the same list. Although you can programmatically add the same object to a list multiple times, the schedule will not do this. For example, if the "Union" method is called to concatenate two lists, the result will not have duplicates. So two joined lists may have less elements than their combined source lists.