Saturday, December 3, 2011

Scripting in MetaVision

In our hospital we use MetaVision as a PDMS (Patient Data Management System). It is a very flexible product, which is it's strength and also it's weakness. Part of the flexibility comes from the possibility to use vbscript as a scripting language to automate tasks, processes, data analyses and/or create user forms.

I will publish my experiences with using scripting in MetaVision.

The first challenge of using vbscript in MetaVision, specifically in forms, is debugging. Debugging script in MetaVision forms is difficult. Moreover, vbscript exceptions thrown at runtime tend to be misleading! This can be a very frustrating trap, in which I have fallen many times. Therefore, the first thing you should do when using vbscript is setup a debugging system.

The most obvious and simple way to debug vbscripts is using message boxes. The following vbscript can be used as a simple helper function that can act to test pre- and postconditions of functions:

Private Function AssertIsTrue(blnIsTrue, strMsg)

 If Not blnIsTrue Then Scripts.MsgBox strMsg

End Function

A precondition is the condition that has to be met for the function to work, and the post condition must be met by the result of the function.

The function can then be used as follows:

Private Function ClearComboBox(cboBox)

 '' Clears a multi select combobox
 AssertIsTrue cboBox.Name = "cboTextComboMulti", "cboBox is not valid"
 
 intUpper = cboBox.Count - 1
 For intIndex = 0 To intUpper
  If cboBox.Selected(Clng(intIndex)) Then _
   cboBox.Selected(Clng(intIndex)) = False
 Next

End Function

In this function I make sure nothing is selected in a combobox. The combobox is passed in, but because there is no type checking in vbscript, I cannot be sure that the parameter cboBox really references a combobox control. Hence the assertion.

In the next blog I will discuss a more advanced debugging solution.

No comments:

Post a Comment