Weight and Med calculations in an iform

85 views
Skip to first unread message

C.E. Coleman

unread,
Feb 22, 2013, 9:58:37 AM2/22/13
to heo-i...@googlegroups.com
Is there a good example of how to calculate this sort of thing:

give 12mg/kg and patient weighs 63kg- calculate 63 x 12  and then add it to another input or static number? 

Are there special considerations? Would prefer straight JS if anyone can toss me a bone. My mind is stuck at getting the input out of wherever it may be into the init statement of a vgr to use as a `number in the load order.

Thanks,

C.E. Coleman

Michael Hudson

unread,
Feb 22, 2013, 10:12:32 AM2/22/13
to heo-i...@googlegroups.com
C.E., 

Here is a plain calc form on old Heparin iform. Not sure if this is what you are looking for.

function initPage(){
var wt = "@@patient_weight@@";

document.getElementById("wt_TF").value=wt;
document.getElementById("dosing_weight").value=document.getElementById("wt_TF").value;
}

if (document.getElementById("dosing_weight").value > 0){
document.forms[0].tf_bolus60.value = Math.round(document.getElementById("acs_dosing_weight").value * 60)  ;
document.forms[0].tf_bolus60_result.value = Math.round(document.getElementById("acs_dosing_weight").value * 60)  ;
document.forms[0].tf_rebolus60_units.value = Math.round(document.getElementById("wt_TF").value * 60)  ;
document.forms[0].tf_rebolus30_units.value = Math.round(document.getElementById("wt_TF").value * 25)  ;
document.forms[0].tf_bolus70.value = Math.round(document.getElementById("dvt_dosing_weight").value * 80)  ;
document.forms[0].tf_bolus70_result.value = Math.round(document.getElementById("dvt_dosing_weight").value * 80)  ;
document.forms[0].tf_rebolus70_units.value = Math.round(document.getElementById("wt_TF").value * 70)  ;
document.forms[0].tf_rebolus35_units.value = Math.round(document.getElementById("wt_TF").value * 35)   ;
}



--
You received this message because you are subscribed to the Google Groups "HEO iForms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to heo-iforms+...@googlegroups.com.
To post to this group, send email to heo-i...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/heo-iforms/-/NY4Pe3O4YjQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

C.E. Coleman

unread,
Feb 22, 2013, 2:21:24 PM2/22/13
to heo-i...@googlegroups.com
Yes, I think that is what I am needing. Being fairly new to this, I wasn't sure how to grab the @@patient.weight@@ and make use of it.


Thanks much!

C.E. Coleman

unread,
Feb 22, 2013, 4:22:34 PM2/22/13
to heo-i...@googlegroups.com
Partially, what it seems I am needing to do is to have a text box for dose x a bodyweight box that displays the @@patient.weight@@, if one is charted, that then outputs the value + 4 for a m/hr rate value.   This value, of course gets shunted off to the VGR.  I think I am going to need a separate function for each of these items and then a function that adds them all together? Am I on the right track?  So far that seems to make the most sense. I get how to create the function to add them all up and add four. Most of my confusion is coming form how to get this pt.weight displayed in the box, and if one is not charted, allow them to put their own value it. I am thinking your function would work there, minus the bolus amounts. I also have a form that sort of does something similar. I see you are using math functions, they also use Math.min and I'm not sure why unless they don't want to display weights outside a certain number range.

I should have eaten my JS Wheaties when they told me to, I suppose.

Scott Morris

unread,
Feb 22, 2013, 4:30:15 PM2/22/13
to heo-i...@googlegroups.com
Just at a glance, it would seem that you're on the right track.  What you'll likely want to do (and what I generally advise to do) is to populate your patient weight into a textbox, put your calculations / form element updates into their own function, and run that function when the page is loaded.  You'll also want to connect that same function to your textbox using the "onchange" event.  That way, if a weight was not originally given or if the user needs to override the weight for whatever reason (dosing weight, IBW, etc), they can do that on their own.

To answer your other unasked question, the "Math.min" function is often used in these calculations if there's a maximum dose.  If you have a med that's 10 mg/kg (max 500), then you'd want either (10 * weight) or (500), whichever is smaller.  That's what Math.min does -- so you can say:

myDose = Math.min((weight*10), 500);

And you can avoid a bunch of if/then statements.

C.E. Coleman

unread,
Mar 2, 2013, 5:19:07 PM3/2/13
to heo-i...@googlegroups.com
I have the calculation part of this working fine but I can't seem to get the weight box to populate. Code is below, any assistance would be appreciated:
  JS:

//function initPage(){
//var wt = "@@patient_weight@@";

//document.getElementById("wt").value=wt;
//document.getElementById("weight").value=document.getElementById("wt").value;}

function calculateDOSE() {
    var wtStr =document.form.mgkg.value;
    if (!wtStr)
        wtStr = '0';
    var htStr = document.form.weight.value;
    if (!htStr)
        htStr = '0';
    var weight = parseFloat(wtStr);
    var height = parseFloat(htStr);
    document.form.TotalDose.value = weight * height + 4;
 
HTML

<input name="" type="checkbox" value="" />iv fluid at 4 ml/hr PLUS  <input type="Text" name="mgkg" size="4"> mg/kg 
<input type="Text" name="weight" id="wt" size="4" > Weight
<input name="clac_wt" type="button" value="calculate" onclick="calculateDOSE()"/>&nbsp;&nbsp;= Dose<input type="Text" name="TotalDose" id="Totaldose" size="4"> mg/kg per hr

Populating the box with my weight seems to be my biggest problem right now. Outside of HEO in Dreamweaver or notepad + I can get the box to populate by pluging in a number intsead of the call for @@patient.weight@@. Once I test the file on the system, it won't populate using any number nor the @@patient.weight@@.  Any advice on how to make this work would be greatly appreciated.

I am also using onload in the body tag and working with someone else's template that already has on onload function to call all their scripts from the server so I hope that is not the source of the js submit buttons not working and throwing errors as I know these don't render like regular HTML. As soon as I get this worked out I have several more to do with advanced math functions.

Jason Murray

unread,
Mar 3, 2013, 10:22:36 AM3/3/13
to heo-i...@googlegroups.com

I would get rid of the document.form.elementname syntax and stick with document.getElementById (or use jquery selectors). I noticed that mgkg doesn’t have an id, weight has a different name than its id, and TotalDose and Totaldose don’t match. They don’t need to, but it can get confusing when they don’t. This works for me, I used document.getElementById and gave an id to mgkg.

 

If you’re still having problems, post your entire html document and I’ll take a look.

 

<html>

<head>

       <title>Weight Calc</title>

 

       <script language="javascript">

 

              function calculateDOSE()

              {

                     var wtStr = document.getElementById("mgkg").value;

                     if (!wtStr)

                           wtStr = '0';

                     var htStr = document.getElementById("wt").value;

                     if (!htStr)

                           htStr = '0';

                     var weight = parseFloat(wtStr);

                     var height = parseFloat(htStr);

                     document.getElementById("Totaldose").value = weight * height + 4;

              }

 

       </script>

</head>

 

<body>

<form>

<input name="" type="checkbox" value="" />iv fluid at 4 ml/hr PLUS  <input type="Text" name="mgkg" id="mgkg" size="4"> mg/kg 

<input type="Text" name="weight" id="wt" size="4" > Weight

<input name="clac_wt" type="button" value="calculate" onclick="calculateDOSE()"/>&nbsp;&nbsp;= Dose<input type="Text" name="TotalDose" id="Totaldose" size="4"> mg/kg per hr

</form>

      

</body>

</html>

--

You received this message because you are subscribed to the Google Groups "HEO iForms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to heo-iforms+...@googlegroups.com.
To post to this group, send email to heo-i...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/heo-iforms/-/V7y0szN4_LoJ.

C.E. Coleman

unread,
Mar 5, 2013, 7:08:32 PM3/5/13
to heo-i...@googlegroups.com
It was deceptive that the JS would work outside HEO, go figure. It does work great! thanks for your help and advice! 

Jason Murray

unread,
Mar 6, 2013, 9:21:22 AM3/6/13
to heo-i...@googlegroups.com
Glad it worked!

What browser are you using to test? Make sure you're using IE7 in quirks mode. All you have to do is use IE7 or later to test, and make sure that your IForms starts with the below html:

The important part is the X-UA-Compatible meta tag, which tells IE to render as IE7. The other thing to notice is that there is no doctype. This will ensure that you're in quirks mode. HEO inserts seemingly useless tags at the very top of the html, so no matter what doctype you specify, if your doctype declaration isn't the very first thing on the page then you'll always be in quirks mode.

Do this and your test environment will match HEO with no surprises.

<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>IForm</title>
</head>
<body>....

________________________________
To view this discussion on the web visit https://groups.google.com/d/msg/heo-iforms/-/V7y0szN4_LoJ <https://groups.google.com/d/msg/heo-iforms/-/V7y0szN4_LoJ> .
For more options, visit https://groups.google.com/groups/opt_out <https://groups.google.com/groups/opt_out> .



--
You received this message because you are subscribed to the Google Groups "HEO iForms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to heo-iforms+...@googlegroups.com.
To post to this group, send email to heo-i...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/heo-iforms/-/wDqdabD5jsgJ.
winmail.dat

C.E. Coleman

unread,
Mar 6, 2013, 10:45:29 PM3/6/13
to heo-i...@googlegroups.com
Well, with you and everyone's help I got is working like a charm....then..I got a change order :(  so now, any advice?
Both of my now-wonderful calculation functions use the same patient weight from the following function, generously provided by Scantron:
function initPage(){
    var wt = 10;
   
    //if(wt==" "){
    //wt=" ";    
       
    //}else{
        document.getElementById("pt_wt").value=wt;  }
   
    Now, I need to change this to use @@patient_weight@@  or if a text box is filled out, use that as the weight to make the calculations instead. I'm thinking
    if none of you have ever had to do this, I might go begging at a Javascript help site. It would use @@pt.weight@@ unless the physician fills out a different weight 
    and they don't want @@pt.weight@@ in a box at all, just on the page. and then I have to make the result useable to the already working calc functions to use in their functions.
    I have no idea how to craft an error for this except an alert js box, not sure if such error can work with VGR.
   
    <tr>
  <td >Weight to be used for calculations for weight based dosing:&nbsp;&nbsp; @@patient.weight@@ kg charted&nbsp;&nbsp;&nbsp;
or&nbsp; &nbsp;<input type="Text" name="pt_wt" id="pt_wt" size="4" > kg entered now&nbsp;&nbsp; (This line needs error checking so if @@patient.weight@@ is null then the box
is filled in)</td></tr>

Any advice about this would be much appreciated. It's like people look at paper and try to force iform and VGR to conform.

C.E. Coleman

C.E. Coleman

unread,
Mar 7, 2013, 9:06:14 AM3/7/13
to heo-i...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages