Where is the data submitted in a form saved in the database?

I am new to DHIS2. I am creating an app that accept form data. I will like to understand where the data that is submitted in a form is saved in the database as well as the api I need to call.

2 Likes

Hello @jetisco4u

The answer to your question depends on the type of data you are collecting

For aggregated data: The data is stored in the datavalue table and you can use the endpoint /api/datavalue

For Tracker type data: several tables are involved in particular: trackedEntityInstance, trackedentityattributevalue, programinstance, programstageinstance, and you also have the following endpoints /api/trackedEntityInstances, /api/enrollments , /api/events

Regards
didate

3 Likes

Thanks this will be very helpful

1 Like

Yes @didate, I agree with @jetisco4u ! Thanks! Very helpful answer! It’s easy to find the api endpoints using api/resources but then when it comes to the tables, one need to search through a very long list! Am I correct?

:slight_smile:

Yes there are many tables in the database. But if you know a little about the structure of the schema, you will see that it is easy to navigate between the tables :wink: .

2 Likes

True! :+1::+1:

In my case, I wanted to create two types of forms one that accept only aggregate number data and one that accept aggregate data as well as other survey question and images in a single event. The existing Apps cannot solve this so I have to create custom form. I just wanted to know for example,

  1. Which api I need to call for each form and which table will warehouse the data.
  2. Since the second form data type covers number, string and object is it possible to capture it in one table that warehouse the data or I have to save it in multiple tables and is there existing table for this type of mixed data?
  3. Where will the image be saved? Is it on the server or somewhere else? In my current tool, we store image on the server and we have a file management system.

cc: @didate @Gassim

Hi @jetisco4u

Just want to clarify that a custom form and a dhis2 model are separate concepts. So for example, if you wanted aggregate data and event data to be collected at the same time, you could do this within an event or tracker program depending on your needs. That program could also accept image uploads, though just be very wary of your server space if your are going to regularly upload images. You would not necessarily need a custom form to do this (though maybe you have a specific layout that needs to be available to your end users?).

Thanks

Thanks @Shurajit_Dutta @Gassim @didate
In the current application I design, we capture the data in different form 5 of them when online the data is submitted real time but in offline mode the data is sent in bulk and each of them go to different api endpoint and different database table. I guess it still possible for me to achieve same. By the way, I will be sending the aggregate data to the aggregate api and the other data with image and signature to a tracker api and data base table. I am yet to get to that stage with DHIS2. But I will like to find out where the image is stored in the server. In our current system, we store the images in a folder in the same directory of the api and store the url to the image in the database. Is that how DHIS2 is configured?

@didate and @Shurajit_Dutta where can I read about the api for events. I am trying to align my project to an event case. And please can I store an array as a value?

Thanks @didate

1 Like

@jetisco4u you decide where the files get stored, you can read more about the file store configuration here : Installation - DHIS2 Documentation

1 Like

@jetisco4u are you referring to storing multiple data values as an array within a single data element? this is currently not possible.

1 Like

I am back now to this project. Yes I am referring to storing multiple data values as an array within a single data element. From my current understanding it is not possible. But I am thing of stringify the json or array data and perse it when I want to use it. I don’t know if its possible or if anyone have tried it.

@Gassim @Shurajit_Dutta I am confused between using aggregate dataValue and program event dataValue to store my data for a dataset package that will be captured during an event program. I have few questions.

  1. If I decide to use the program event dataValue to store my data, can I use the virtual and analytics apps can I use to process the data? If none fit my need can I build a custom analytic app?

  2. Is it possible to setup an event program and saved the captured data as an aggregate data through the /api/dataValue rather than the /api/tracker/events endpoint?

  3. I am creating the data element as a json file to upload it. What is the implication of setting AGGREGATE as domainType instead of TRACKER if I am storing my data in /api/dataValue if I setup the program as an event?

  4. If I want to setup indicator for my data which of indicator and program indicator should I use. I couldn’t find a documentation to clarify this.

Couple things to clarify.

  1. You will not have any issues accessing this data in the already existing dhis2 analysis apps.

2/3 As you are using an event program, then you need to set the domain type of your data elements to tracker. Data elements with the aggregate domain type can only be used in aggregate data sets. As you are creating an event type program, and an event type program always consists of multiple events, the event values will be available via /api/tracker/events

  1. Depends what you are calculating. A program indicator is often a filter of something specific in your event program. For example, if you want to access a count of the number of males who received a given treatment, then you might create a program indicator to count this. Indicators do not allow you to filter event data directly, but you can use many sources to create an indicator including program indicators. So for example if you wanted the proportion of males who received a given treatment you could create an indicator that takes
    -info from your program indicator as the numerator
    -info on the number of males as aggregate data as the denominator

This is just an example but hopefully it gives you a general idea.

1 Like

Thank you for the clarification. Let me try and create a demo app to test what is possible.

1 Like