← Back to team overview

dhis2-devs team mailing list archive

Re: Auto-calculated data in entry forms

 

Hi there,

Great that the javascript worked out for you. Unfortunately, I'm not an expert. I had a look at the code below but a simple copy-paste doesn't seem to be working (after modifying the references). Would it be possible that there's an event missing to trigger the calculation? How would that work?

Thanks a lot!

Robin

From: Pamod Amarakoon [mailto:pamodm@xxxxxxxxx]
Sent: 02 September 2014 06:54
To: Ngoc Thanh Nguyen
Cc: dhis2-devs; Robin Martens; DHIS 2 Users list; Jason Pickering
Subject: Re: [Dhis2-devs] Auto-calculated data in entry forms

Hi,
Thanks a lot. In fact I'm a medical doctor and have limited knowledhe in Javascript. I managed to get it done with following javascript I created.

height enterd in cm and weight in kg.

<script type="text/javascript">

function updateBMI() {
var ht = document.getElementById("HeightID-val").value;
var wt = document.getElementById("WeightID-val").value;
if(ht!="" && wt!=""){
var bmi = wt/(ht*ht/10000);
bmi = +bmi.toFixed(2);
}else{
var bmi ="Enter Height and Weight";
}
var inputbmi= document.getElementById("BMI-ID-val");
inputbmi.value = bmi;
}
updateBMI();

</script>
It serves the purpose it seems. Pls suggest any modifications

On Mon, Sep 1, 2014 at 11:52 PM, Ngoc Thanh Nguyen <thanh.hispvietnam@xxxxxxxxx<mailto:thanh.hispvietnam@xxxxxxxxx>> wrote:

yes you can use custom data entry form and add some js script like onchange event on weight and height.

the event handler should then calculate the bmi and update the text field bmi.

do you have any technical person to do this? if not give me your account i can help
On Sep 2, 2014 12:26 AM, "Pamod Amarakoon" <pamodm@xxxxxxxxx<mailto:pamodm@xxxxxxxxx>> wrote:
I'd like to add something to this.
For example, if we have a data entry form (BMI) for a program stage if we have height and weight input boxes/data elements is there a way to calculate BMI?
is it only possible by using javascript/webapp

On Mon, Sep 1, 2014 at 10:21 PM, Ngoc Thanh Nguyen <thanh.hispvietnam@xxxxxxxxx<mailto:thanh.hispvietnam@xxxxxxxxx>> wrote:
Hi

I believe the calculated data value (now as indicator) can only be seen after an aggregation is run.
In addition, in some forms in some countries like VN, auto-calculated data elements some time can be input by users.

In VN, we use Javascript to achieve this. However, it is quite complicated. Imagine that you have to rebuild a spreadsheet engine.

Important lesson learnt was if a dataelement is auto-calculated, make sure no one can change it manually. Otherwise, you end up with very low data quality.

Thanh

On Mon, Sep 1, 2014 at 11:15 PM, Jason Pickering <jason.p.pickering@xxxxxxxxx<mailto:jason.p.pickering@xxxxxxxxx>> wrote:
Hi Robin,

You can simply use an indicator to do this.

In case you have not seen it, we have extensive documentation on the use of indicators here

https://www.dhis2.org/doc/snapshot/en/user/html/ch13.html#indicator_maintenance

It should also be possible to calculate the value from other data, not contained in the data entry form, IF it exists for the same orgunit and period.

Best regards,
Jason


On Mon, Sep 1, 2014 at 5:48 PM, Robin Martens <martens@xxxxxxx<mailto:martens@xxxxxxx>> wrote:
Dear all,

Does anyone know if there's a way to have auto-calculated fields in data entry forms? This auto-calculated field would then be available for further reporting and indicator calculation (i.e. it is a data element calculated based on other data elements in the same entry form).

Actually, if it would be possible to calculate data elements based on other data elements outside of a data form, that would be great too (but if I remember well this is currently not possible).

Thanks for any ideas,

Robin

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx<mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx<mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx<mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp



--
Pamod



--
Pamod

References