I want to remove all organization units assigned to a data set from the database using a SQL statement.
my question is which table the organisation unites are stored in database
I would strongly advise that you do this via the API instead. The database schema for DHIS2 is quite complex, and most operations involve updating linked records in multiple tables; the API will handle this automatically for you, but if you do it manually then you risk creating inconsistent/orphaned database records, which could cause unexpected behaviours in DHIS2.
What is the exact operation you want to do? (I could try to suggest a solution using the API.)
@SamuelJohnson
I want to remove all HFs that were assigned to the dataset. I have about 2500 HFs on hierarchy level 4. Thus, I will use SQL statements using their parent.
Why don’t you use the Maintenance app and configure the data set settings manually from the UI? With just one click you can deselect all the HFs in level 4. There’s no need to use the API or run a SQL query for this.
Thanks @SamuelJohnson for the help too
@Gassim Thanks a lot. What I need is different. I want to remove all HFs of the governorate, for example, Governorate A, but the method you provided will remove all HFs of all governorates.
It’s generally not advised to update the db directly (you might corrupt the db or end up in state where dhis2 is not aware of changes, the orgunits model is probably heavily cached at application level)
If you are
- a power user and
- know enough javascript and
- sure of what you are doing
- made a backup prior such mass changes
you can use dhis2 taskr to automate such task
https://github.com/BLSQ/dhis2-taskr/blob/master/README.md and the dhis2 api to “mass modify” the datasets.
Hello all,
Another way to easily remove OU assigned to DS, is to export the DataSet in Import/Export module with “Metadata dependency export” and delete organisationUnits content without deleting organisationUnits tag and re-import it.
Btw the name of the table of DS’s OU is datasetsource, but please listen to the above advice from the experts.
Regards;