These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Forms Calculations

Bill1234
Registered: Feb 8 2009
Posts: 10
Answered

I have two questions which are:

1. I need to calculate a dose but limit the amount to no more than a set amount (ie, max dose of 20 grams). If the calculated amount exceeds 20 grams, then I would need to have 20 grams listed in the dose field.

2. Can you allow an override in a field for a dose calculated if you choose to manually round the answer up or down?

Bill B.

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
For #1 you would have to supply more information if you're seeking advice on the specific code to use. Are you using Acrobat or LiveCycle Designer to create your form? How is the dose calculated? Is the dose for humans?

For #2, the answer is yes.

George
Bill1234
Registered: Feb 8 2009
Posts: 10
I am using Acrobat to create a preprinted order form for medication ordering/administration. In one of the fields I need to calculate a dose (eg, 270 mgs/kg not to exceed 20,000 mgs). I want the dose calculated to appear in the dose field unless it exceeds 20,000 mgs. If it exceeds 20,000 mgs then list 20,000 mg as the dose to be given.

Also, there are calculated fields embedded in this form that, depending on the amount calculated, may need to be rounded to the nearest vial size to avoid wasting medication (eg, a calculated dose of 43 mg might be rounded down to 40mg which is the vial size available). This would be a judgment call on the part of the practitioner. I want to know how to manually adjust the calculated dose in those cases. I have experimented with this and cannot change the calculated dose without removing the formula from the field.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
OK, so I'l assume there is another field on the form that contains the subject's weight in kilograms. There are two general approaches you can take. One is to use a custom validation script in the weight field that sets the value of the dosage field. The other is to make the dosage field a calculated field and use a custom calculation script. The first approach makes it easier to override the value that is calculated, but you can still do this if you use a custom calculation script.

For the first approach, you can do something like the following, but please consider this to be the minimum to demonstrate the basic idea. If this is to be used for determining medicine dosages for humans, you will need to do the appropriate exhaustive testing.

(function () { // Custom validation for the weight field// It is assumed the field value represents a weight in kilograms and is a valid number// within a range that makes sense. This should be thoroughly validated. // Get the value that the user entered onto this field, as a numbervar subj_weight = +event.value; // Determine the dosevar dose = 270 * subj_weight; // If dose exceeds 20000, set it at 20000if (dose > 20000) dose = 20000; // Set the value of the dose fieldgetField("dose").value = util.printf("%d", dose); })();

If for some reason you want to use a custom calculation script in the dose field, you could do something like:

(function () { // Get a reference to the subject weight fieldvar f = getField("subj_weight"); // Only proceed if the field that triggered this script is the subject weight field// This allows the user to override the value determined below.if (event.source !== f) return; // Get the subject's weight, as a numbervar subj_weight = +f.value; // Determine the dosevar dose = 270 * subj_weight; // If dose exceeds 20000, set it at 20000if (dose > 20000) dose = 20000; // Set the value of this field to the doseevent.value = util.printf("%d", dose); })();

Again, this is intended a general guidance, not production code.

George