Retrieve previous month data value of a data element and put it in the current month data entry

Hi, everyone.

How can I retrieve the data values of previous month and show it in the current months data entry?

Any help on how how I can do this is DHIS2 is welcome?

1 Like

Hi Fernando,

I’d tentatively suggest you look at Predictors (https://docs.dhis2.org/master/en/user/html/manage_predictor.html). I’ve never implemented them myself (perhaps someone who has can chime in with advice?), but they’re designed for exactly the use case you have here - they allow you to automatically (as scheduled) calculate the current value for a data element based on values held in other data elements over a specified period (eg last month).

Since I’ve not worked with them, and have no idea how ‘buggy’ they are, no warranties (express or implied) can be provided. :wink: If Predictors do turn out to be a viable solution for you, please do share your experience with the community.

Cheers, Sam.

2 Likes

Hi @fernando,

I wrote the below script for opening balance calculation:

dhis2.util.on( ‘dhis2.de.event.formReady’, function( event,iReVg2xgFPL ) {
var periodN= $( ‘#selectedPeriodId’ ).val();// From DHIS2 Selection Param
var nextPeriod=(+periodN) + (+1); //201611,201612,201613
var nextPeriodSeperate=periodN.toString().substring(0, 4);
var year=parseInt(nextPeriodSeperate.trim());
var month=parseInt(periodN % 100);
if(month==12){
year++;
month=01;
nextPeriod=year+‘01’;
}
$(’.selectedDate’).val(nextPeriod);
});

You will get detail on this post: http://dhis2trainingland.com/eportal/?tutorial=how-to-calculate-previous-month-value-in-dhis2-data-entry-form

Basically, I’m calculating the closing balance and saving it for next period and getting automatically opening balance value in the next period.

Thanks

1 Like

Thank you, Samuel, for your suggestions and help.

1 Like

Hi, Julhas.

Thank you for your help.

1 Like

Hi Julhas, I hope all is well. This is very helpful. I just don’t know where/how exactly to put the code. Do you mind to guide me?

1 Like

Hi Norberto,

Sure, you can ping me on skype: juhas08.

Thanks

2 Likes

Hi Julhas, I sent you an invitation yesterday on skype. Can you please add me with norbertob.pi

Thanks,

1 Like

Hi Norberto, I didn’t get your invitation. :slightly_smiling_face: Let me add you.

Thanks

1 Like

Hi @fernando,

@SamuelJohnson is exactly correct. Predictors enable you to do this without having to make any custom scripts. You’re use-case is fairly simple.

  1. Make a new data element for the value that you want to show in the current data entry form
  2. Make a new predictor and assign the output data element to the new data element
  3. Make a predictor that has a generator as SUM(#data element UID from previous month)
  4. Make your predictor sequential sample count to 1 and annual to 0
  5. Assign your predictor to the org unit level that is capturing the data.
  6. Use the scheduler app to schedule your predictor to run automatically.
  7. Assign your new data element to your data set that you want it to appear in.

Hope this helps and please let me know if you have any questions.

Scott

3 Likes

Informative!!!:grinning:

1 Like

Hi @Scott,

I will follow your instructions. If I get any problem, I will say something.

1 Like