← Back to team overview

dhis2-devs team mailing list archive

Re: Formulas and connections between DataElements and Indicators

 

Hi Jose

On 14 July 2013 20:40, Jose Garcia Muñoz <josemp10@xxxxxxxxx> wrote:

>
> Thanks Bob!
>
> You are right in the sense that the indicator becomes redundant, but I
> think we will still need it because we can train the end-users in the use
> of formulas and indicators inside DHIS2, but stored procedures is quite
> hard if they don't have much technical skills. So the idea I think is to
> define a function in plpgsql to make a copy of the value of the indicator
> into the dataelement (knowinI don-g the period and source of course)
> linking the function to a trigger. Please correct me if I am wrong, as I
> don't have much experience using triggers.
>

I don't think storing the value of the indicator is the main issue.  In
fact indicator values are not generally stored, except as a result of
aggregation into the datamart.  And with the newer analytics I don't think
the value is necessarily stored at all.  They are calculated on the fly
(Lars will know better).

My understanding of your problem is that the indicator formula itself would
need to be reconstructed because you might change the number of
dataelements in the dataset which contribute to it's sum.  So I thought
that what your trigger function would be doing is to simply sum the number
of true data values in the dataset and use that to populate the dataelement.

I agree this is not something you would expect users to do, but I guess you
would write the trigger function in such a way that it would dynamically
calculate the sum so its inner workings would be hidden from users.

Caveat: I am also not a postgres trigger expert but I am reasonably sure it
is doable.  Perhaps you could trigger it on the data completeness update?
 Jason might have some ideas.

If the trigger is intimidating you might also execute the function as a
scheduled cron job but then you would be facing delays before the system
reacts to the new data.  I think I would investigate the trigger approach.

Bob


>
> Also, when you introduce an indicator into a dataset, when does the
> indicator update its value? (when you click in the complete button of the
> dataentry maybe?) and which table stores the value of the indicator?
> (attributevalue?)
>
> Thanks
> Jose
>
>
> On Sun, Jul 14, 2013 at 12:40 PM, Bob Jolliffe <bobjolliffe@xxxxxxxxx>wrote:
>
>> Hi Jose
>>
>> Copying to devs list as there may be greater wisdom there :-)
>>
>> I think your approach can work .. ie store your historical scores as
>> dataelement.
>>
>> Regarding regenerating the formula, again I think you are right and will
>> have to resort to a database function as I can't think of an easy
>> workaround through the application and you really don't want to do these
>> manually.
>>
>> Though I start to think that if you go down this route perhaps the
>> indicator becomes redundant.  You will have your formula as stored proc in
>> database and can probably use that to populate your "score" dataelement
>> directly.
>>
>> Bob
>>
>>
>> On 14 July 2013 12:15, Jose Garcia Muñoz <josemp10@xxxxxxxxx> wrote:
>>
>>>
>>> Hi guys,
>>>
>>> How are you doing?
>>>
>>> first at all, maybe I should send this email to the dev user list, if
>>> so, sorry about that and please feel free to resend it.
>>>
>>> I am dealing with several forms in DHIS2 with all its DE of the
>>> "trueOnly" type value. For each form, one final score is calculated
>>> depending on the number of questions answered by the users and one weight
>>> associated for each question. Of course, we have defined an indicator to
>>> calculate this value. But, what about when the number of questions (or the
>>> different weights) change along the time (so the formula needs to be
>>> redefined) and we still need to maintain the historical score of the "old"
>>> formulas?
>>>
>>> We were thinking about the possibility of creating a data element for
>>> each form to store the historical scores. Does it make sense? If so, the
>>> big challenge will be the connection of the indicator (when its value is
>>> calculated) with the Data Element. Some ideas about how could I deal with
>>> this? Create a trigger inside the database (with an 'on completion' event)?
>>>
>>> Best regards
>>> Jose
>>>
>>
>>
>

References