I am setting up organization unit for a project. There is a path and translation fields in the database table. Where is the value coming from or what is the logic for inserting the two?
Also I downloaded the latest demo database and realize that some fields such as type, latitude and longitude are omitted. Is it deliberate.
Ideally you should use the api to create objects in dhis2 not directly injecting/updating stuff via sql
it bypasses a lot of access right, validations, and calculated fields like the path property, cache invalidations.
here the path is deduced from the id or the orgunit and the parent id (and it’s ancestors)
to learn the api, I would advise that you use the app via the maintenance pages and look in the browser network view for the appropriate payload/method/endpoint.
You might also be interested by DHIS2 App Hub
to use the api from your browser
// press crtl-r to run
const api = await dhis2.api();
try {
const ou = await api.post("organisationUnits", {
name: "demo",
shortName: "hello",
openingDate: "2022-08-02"
});
return ou;
} catch (e) {
return e;
}
for longitude/latitude. the fields has been renamed and change a bit the type.
it’s now in db it’s postgis geometry field and the api is the geometry field.
previous it was a varchar coordinates and coordinate field
@Stephan_Mestach thanks for the tip. In my case I am seeding data into the database from scratch. Is there a way to bulk upload data via the api? The part I am seeding data for is the maintenance app data. I am working on a blank db.
you can feed a json ( or via the metatada importer it will show you what to do through the api)
depending on the size of what you want to import (async will be better)
from the documentation point of view you can have a look at
Which version of DHIS are you using? Also, the org unit data which you want in the new project, is this already present in other DHIS instance? Or are you creating them from scratch ?
Creating from scratch. When I upload the data from the db with sql, the orunitgroupset and orgunitgroup show well in the frontend but the organisationunit data didn’t show even though it’s in the database. It is more convenient for me to insert the data from sql bc I am a database administrator. But if I get a clear documentation for bulk uploading the data I can also do it.
Can you open server-url/api/organisationUnits.json?order=lastUpdated:desc and check if the org units you have added are already visible?
Yes, there is no option for hierarchy level in maintenance app because the new org unit will be added as child of the selected org unit from the org tree.
@rithvik I work around the SQL INSERT statement and the hierarchy is now working. However, the changes I made in the database reflect on the server api link server-url/api/organisationUnits.json?order=lastUpdated:desc as well as the database. But this changes don’t reflect yet in the maintenance app and the event report app even after I refresh the page, logout and login back.
@jetisco4u Please feel free to ask for clarification or more explaination here as well. It will help updating the docs when there’s something not clear. And, I agree with @Kenyuri then Import/Export app is supposed to help you import Org Units, from scratch.
@Gassim@Kenyuri@rithvik thanks for the tips. I was able to upload the orgunit data using sql INSERT command. I want to create the metadata and will like to try to use the import app. Is there a sample json or csv document that can be upload with all the basic data?