Compute Element

From DOC

Jump to: navigation, search

A "compute" element is what makes a trim active. As the name implies, a compute method is used to, for example, compute a body mass index based using the patient weight and height. Also, you can use a compute to "harvest" additional information from the patient record into the TRIM. The following compute might be used to calculate the dates for a radiation treatment plan.

<trim ...>
  <act classCode="PROC" moodCode="INT">
    ...
    <compute>
      <type>com.myCo.compute.ComputePlan</type>
      <property name="template">
        <value xsi:type="xs:string">proc/rqo/radiation/breast</value>
      </property>
    </compute>
  </act>
</trim>

Compute will be called multiple times so your code should be relatively efficient. Also, a compute must avoid doing trivial "inserts" into the Trim since you might end up with multiple insertions where one is desired. Rather, the compute should "insert-if-not-present" or "remove-if-present".

Another technique often used is the enable-once approach. The Tolven InsertAct compute has an enable flag which can be set by user action or by Javascript on the browser. When the compute, in this case, as inserted the specified act, the enable flag is set to false. Thus, each time the enable flag is set to true, a new act is inserted. This enable flag is different from the enabled flag on an act, entity, or role.

You can and should add custom "compute" methods to enhance trim behavior. A custom compute class, which must be a subclass of org.tolven.process.ComputeBase, is added to the ejb section of your plugin (see Developer's Guide). Be sure to name your custom compute with your prefix, not "org.tolven." You then just reference it from the TRIM by name.

Compute methods are only called prior to submit. Trims are immutable after submission and therefore a compute no longer can be applied after submit.

If an act/entity/role element has more than one compute elements, each is called in in the order declared.

The <compute> element can also be used as a validator. This allows the compute method on the server server to feed back information to the wizard in the form of an error message. Such error messages are displayed as Java Server Faces messages.

While a compute element can modify the Trim, it has no control over the wizard form being displayed on the browser. Therefore, it is the responsibility of the form to respond to the updated trim either wholesale as a refresh of the entire wizard or locally using embedded Javascript. On the other hand, if the compute makes a change to the Trim that only needs to be displayed on the final submit page (the drilldown page), the process is trivial since the submit page always requires a round trip to the server and a fresh display of the trim.

A Javascript compute is technically not a Compute Element as described here - it simply fills in form fields which are uploaded to the trim. One example of this behavior can be seen in the BodyMassIndex wizard. Since the BMI must be displayed on the wizard entry page, not the submit (drilldown) page, it does not use a server-based compute. In the following, the evalFunc attribute contains the function to be called.

	<td  evalFunc="bmiCalFnc('#{menu.elementLabel}')" width="15%" style="text-align: left;"></td>

This function does the actual work of computing BMI from height and weight fields and stores it in the BMI field on the form. This field then gets uploaded, along with any other user-entered fields, to the server and therefore into the trim.

Personal tools