AVImark supplies a number application interfacing objects, or COM objects, that may be used in virtually any programming language that supports OLE automation, e.g. Delphi, Visual Basic, C++ etc. Examples in this document will be written in Visual Basic. Note that in order for the COM objects to be accessible, the AVImark program must be running on the desktop.

The AVImark objects either require, or supply ‘handles’ to records and files that exist in the AVImark database. A ‘file handle’ is simply a number which identifies each file. This number starts from 1. For example, the client file is indicated by the number 1. The client file is also identified by its name on the hard disk as CLIENT.VM$. If convenient, this name can be supplied to retrieve the unique identifier for the file.

A ‘record handle’ is a number which identifies each record in the file. This number starts from 1. For example, each patient for a given client would have a corresponding, invisible, record handle. Incidentally, the account number for a client is always the same number as the record handle which identifies that client.

Note that if a record handle cannot be retrieved, then the value of 0 will be returned.

Methods which return an array of record handles (e.g. AVIClient.GetPatientHandles) never return deleted records in the result set. If random records are accessed, for example through AVIFile.GetFieldValues, then the result data should be checked to be sure that the record has not been deleted. This is done by checking the ‘???_RECD’ field value. This field has a value of ‘A’ for active records.

AVImark.AVICID

GetClientHandle: Integer – Retrieves the record handle, and thus the account number, of the client currently open on AVImark’s Client Information Display. If no client is open, then the value of 0 will be returned.

GetHistoryHandle: Integer – Retrieves the record handle of the currently selected medical history entry. If no history is displayed, then the value of 0 will be returned.

GetPatientHandle: Integer – Retrieves the record handle of the currently selected patient. If no patient is open, then the value of 0 will be returned.

SetClientHandle(ClientHandle: Integer) – This method will cause AVImark to open a new client on the Client Information Display whose account number matches the supplied record handle.

SetPatientHandle(PatientHandle: Integer) – This method will cause AVImark to open a new patient on the Client Information Display whose record handle matches the supplied record handle. The patient’s owner and associated medical history will be displayed as well.

AVImark.AVICensus

GetPatientHandles: OleVariant – Retrieves an array of record handles corresponding to patients that are currently checked-in and are displayed in AVImark’s census list.

AVImark.AVIClient

GetFirstByName(const NameKey: WideString): Integer – Retrieves the first record handle for the client whose last name is equal to or greater than the supplied name. Note that the supplied name, NameKey may be a partial value. Note also that the returned client’s name may not match the supplied NameKey if none are found. For instance, if there are no ‘Smith’ names in a database, and the supplied NameKey is ‘Smith’ then the first match may be a client named ‘Smithson’. If no matches whatsoever are found then the value of 0 is returned.

GetNextByName: Integer – Use this method in conjunction with GetFirstByName. This method will return the next client whose name is greater than the last name of the client most recently found by GetFirstByName or GetNextByName. If no matches are found, then the value of 0 is returned.

GetFirstByPhone(const PhoneKey: WideString): Integer – This method works very much like GetFirstByName, only a phone number match is performed. Note that this method has a dual capability in that it can be used to search for clients by folder number as well.

GetNextByPhone: Integer -- See GetFirstByPhone and GetNextByName.

GetPatientHandles(ClientHandle: Integer; IncludeInactive: WordBool): OleVariant -- Retrieves an array of record handles for patients that belong to the supplied client handle. The IncludeInactive parameter can be used to filter the retrieval of patients that are deceased or moved.

GetAccountingHandles(ClientHandle: Integer): OleVariant -- Retrieves an array of record handles for accounting entries that exist for the supplied client handle.

GetByFolder(const FolderKey: WideString): Integer – This method attempts to locate the client having the supplied folder number. If a client having the supplied folder number is not found, a value of zero is returned.

AVImark.AVIEntry

GetByCode(TableCode, EntryCode: WideString): Integer – Retrieves the record handle of the system table entry whose code matches the EntryCode supplied. The TableCode must also be provided. For example, if the breed code, ‘DSH’ is searched for, then TableCode must be set to ‘BREEDS’ and EntryCode set to ‘DSH’.

AVImark.AVIFile

GetFileHandle(FileName: WideString): Integer – Retrieves the file handle for the supplied file name.

GetFileHandles: OleVariant -- Retrieves an array of all file handles in AVImark. For instance, the file handle for the client file (CLIENT.VM$) is 1.

GetFileNames: OleVariant – Retrieves an array of file names existing in the AVImark database.

GetRecordCounts: OleVariant -- Retrieves an array of the number of records in all AVImark files. For instance, the file size for file handle 1 (CLIENT.VM$) might be 3,203 records, representing 3,203 clients.

GetFieldNames(FileHandle: Integer): OleVariant – Retrieves an array of field names for the given file.

GetFieldValues(FileHandle, RecordHandle: Integer): OleVariant – Retrieves an array of field values. The order of the fields in the array correspond to the order of the field names supplied in GetFieldNames.

GetFieldValuesByName(FileHandle, RecordHandle: Integer; FieldNames: OleVariant): OleVariant – This method is identical to GetFieldValues except that instead of all field values being returned, only the fields supplied in the parameter, FieldNames, will be returned. FieldNames must be an array of strings identifying each field. To see a sample list of field names, use the method GetFieldNames.

AddRecord(FileHandle: Integer): Integer – Adds a record to the file specified by FileHandle and returns the handle of the new record.

AVImark.AVIHistory

GetInventoryUsedHandles(HistoryHandle: Integer): OleVariant – Retrieves an array of record handles corresponding to ‘inventory used’ attached to the supplied history handle. These record handles indicate records in the file, USAGE.VM$

GetFirstByDate(const DateString: WideString;PatientHandle: Integer): Integer – Retrieves the most recently added medical history record handle for the specified patient that has a date that is equal to or earlier than the specified date. Note that use of a null value for date will result in the most recently added medical history record being retrieved.

GetNextByDate: Integer – For the specified patient, this method retrieves the medical history record that was entered in the patient’s medical history before the medical history entry that was last accessed via the GetFirstByDate or GetNextByDate methods.

GetLastByDate(const DateString: WideString; PatientHandle: Integer): Integer – Retrieves the oldest medical history record handle for the specified patient that has a date that is equal to or later than the specified date. Note that the use of a null value for this date parameter will allow you to access the oldest medical history record for the specified patient.

GetPrevByDate: Integer – For the specified patient, this method retrieves the medical history record that was entered in the patient’s medical history after the medical history entry that was last accessed via the GetLastByDate or GetPrevByDate methods.

GetFirstByCode(const CodeKey: WideString;PatientHandle: Integer): Integer – Retrieves the most recently added medical history record handle for the specified patient that has the specified treatment, item, or diagnosis code and has a date equal to or earlier than the specified date. Note that use of a null value for date will result in the most recently added medical history record being retrieved.

GetNextByCode: Integer – For the specified patient, this method retrieves the medical history record that has the specified code and that was entered in the patient’s medical history before the medical history entry that was last accessed via the GetFirstByCode or GetNextByCode methods.

GetLastByCode(const CodeKey: WideString;PatientHandle: Integer): Integer – Retrieves the most recently added medical history record handle for the specified patient that has the specified treatment, item, or diagnosis code and has a date equal to or earlier than the specified date. Note that use of a null value for date will result in the most recently added medical history record being retrieved.

GetPrevByCode: Integer – For the specified patient, this method retrieves the medical history record that has the specified code and that was entered in the patient’s medical history after the medical history entry that was last accessed via the GetLastByCode or GetPrevByCode methods.

AVImark.AVIPatient

GetFirstByName(const NameKey: WideString; ClientHandle: Integer): Integer – Retrieves the record handle of the patient that belongs to the specified client and whose name is equal to or greater than the name specified by the NameKey. See AVImark.AVIClient’s, GetFirstByName for further documentation.

GetNextByName: Integer – See GetFirstByName and AVImark.AVIClient’s, GetNextByName.

GetHistoryHandles(PatientHandle: Integer): OleVariant – Retrieves an array of record handles for medical history belonging to the supplied patient handle. These record handles indicate records in SERVICE.VM$.

GetReminderHandles(PatientHandle: Integer; IncludeInAppropriate:

WordBool): OleVariant – Retrieves an array of record handles for reminders belonging to the supplied patient handle. These handles indicate records in PROC.VM$

GetAppointmentHandles(PatientHandle: Integer): OleVariant -- Retrieves an array of record handles for appointments belonging to the supplied patient handle. These handles indicate records in APPOINT.VM$

AddPatient(ClientHandle: Integer): Integer – Adds a new patient record to AVImark and returns the patient handle of the newly added record.

GetByTagNo(const TagNoKey: WideString): Integer – Attempts to locate the patient record having the supplied rabies tag number. If no patients have the specified tag number, a value of zero is returned.

GetByMicrochip(const MicrochipKey: WideString): Integer – Attempts to locate the patient record having the supplied microchip (e.g. AVID) number. If such a patient is not found, a value of zero is returned.

GetByFolder(const FolderKey: WideString): Integer – Attempts to locate the patient record having the supplied FolderKey value. If no patients have the specified folder number, a value of zero is returned.

GetViewHandles(PatientHandle: Integer; const ViewName: WideString): OleVariant; Retrieves an array of record handles for medical history belonging to the supplied patient handle, qualified by the named ViewName string. Note that the ViewName parameter can either give the name of any of the AVImark medical history view tabs on the CID, or any other word or portion of a word that appears in the Description field of the desired medical history entries. For example, a ViewName value of “Rx” would retrieve an array of all prescription entries in medical history, whereas “spay” would retrieve an array of all entries in medical history whose Description contained the word “spay”.

AVImark.AVIInventory

GetByCode(const Code: WideString): Integer – Retrieves the record handle of the inventory record whose code matches the supplied Code. This record handle indicates a record in the file, ITEM.VM$

AVImark.AVITreatment

GetByCode(const Code: WideString): Integer -- Retrieves the record handle of the treatment record whose code matches the supplied Code. This record handle indicates a record in the file, TREAT.VM$

Examples

Listing all fields for an open client:

This example was created in Microsoft Word using a macro.

Public Sub Test()

Dim FileObject As Object

Dim CIDObject As Object

Dim FieldNames, FieldValues As Variant

Dim Index As Integer

Dim ClientHandle, RecordHandle As Integer

Set FileObject = CreateObject("AVImark.AVIFile")

ClientHandle = FileObject.GetFileHandle(“CLIENT.VM$”)

FieldNames = FileObject.GetFieldNames(ClientHandle)

Set CIDObject = CreateObject("AVImark.AVICID")

‘WARNING. The document will be cleared by this command…

ActiveDocument.Content.Delete

RecordHandle = CIDObject.GetClientHandle

FieldValues = FileObject.GetFieldValues(ClientHandle, RecordHandle)

For Index = LBound(FieldNames) To UBound(FieldNames)

ActiveDocument.Content.InsertParagraphAfter

If Not IsNull(FieldValues(Index)) Then

ActiveDocument.Content.InsertAfter (FieldNames(Index) & "=" & FieldValues(Index))

Else

ActiveDocument.Content.InsertAfter (FieldNames(Index) & " = Null")

End If

Next

End Sub

Searching for clients by name:

This example uses a TextBox, a CommandButton, and a ListBox to allow searching for clients by name. When the search button is clicked, the list box is populated with the names of clients that were found. When the list box is clicked, the current client open in AVImark is changed to the selected client in the list box.

Dim FileObject As Object

Dim ClientObject As Object

Dim CIDObject As Object

Private Sub ResultListBox_Click()

Dim ClientHandle As Integer

TempStr = Trim(ResultListBox.List(ResultListBox.ListIndex))

TempInt = InStr(1, TempStr, " ", vbTextCompare)

ClientHandle = Str(Mid(TempStr, 1, TempInt - 1))

CIDObject.SetClientHandle (ClientHandle)

End Sub

Private Sub SearchNameButton_Click()

Dim ClientHandle As Variant

Dim FieldNames(0 To 1) As String

Dim FieldValues As Variant

Dim NameKey As String

Dim Done As Boolean

FieldNames(0) = "CLIENT_LAST"

FieldNames(1) = "CLIENT_FIRST"

NameKey = UCase(NameTextBox.Text)

ResultListBox.Clear

ClientHandle = ClientObject.GetFirstByName(NameKey)

Done = False

Do While (ClientHandle > 0) And Not Done

FieldValues = FileObject.GetFieldValuesByName(FileObject.GetFileHandle("CLIENT.VM$"), ClientHandle, FieldNames)

If Mid(UCase(FieldValues(0)), 1, Len(NameTextBox.Text)) > UCase(NameTextBox.Text) Then

Done = True

End If

If Not Done Then

ResultListBox.AddItem (Str(ClientHandle) & " " & FieldValues(0) & ", " & FieldValues(1))

ClientHandle = ClientObject.GetNextByName(NameKey)

End If

Loop

End Sub

Private Sub UserForm_Activate()

Set FileObject = CreateObject("AVImark.AVIFile")

Set ClientObject = CreateObject("AVImark.AVIClient")

Set CIDObject = CreateObject("AVImark.AVICID")

End Sub

Exporting patient information to a text file:

This example creates a text file, then iterates over all patients in the database, exporting client and patient data to the text file. Note that the patient ‘RECD’ field is checked to be sure that the exported data does not include deleted records. As an example, the program filters patients so that only felines that are not deceased are exported. The ‘ENTRY.VM$’ file is used to lookup the breed and color names for each patient.

Public Sub Export()

Dim PatientFieldNames(9) As String

Dim ClientFieldNames(0) As String

Dim EntryFieldNames(1) As String

Dim FileSysObj, ATextFile, AVIFileObj, AVIEntryObj As Variant