Script to disassociate Orgunit with Datavalue

Dear All,

Is there there anyone with a script to disassociate an Orgunit from all associated programs or data sets so I can be able to delete it from within DHIS2?

Thank you.

···

Walusiku J. Muyunda

Cell: +260967006614
Cell: +260971000614

Cell: +260953063387

"We have heaven to win and hell to shun, our lives testify better!"

Hi there!

You can have a look here https://github.com/dhis2/dhis2-utils/blob/master/resources/sql/delete_orgunit_with_data.sql

which will delete the site and all object associated with it. You should supply the UID of the orgunit you wish to delete as a paramater to the Postgresql function.

You may also need to update the script to suit the version of DHIS2 you are running.

As usual, be sure to test this on a development database first!

Best regards,

Jason

···

Jason P. Pickering
email: jason.p.pickering@gmail.com
tel:+46764147049

Thank you Jason, this will be very helpful. Am using v2.28 and hope the script will run without complaints.

Regards.

···

Walusiku J. Muyunda

Cell: +260967006614
Cell: +260971000614

Cell: +260953063387

"We have heaven to win and hell to shun, our lives testify better!"

Hi Jason,

Please help with syntax for this line:

EXECUTE ‘SELECT organisationunitid from organisationunit where uid = ‘tPR9B5xETb’’’’ || $1 || ‘’’’ INTO organisationunitid; Is this where I need to specify the uid?

Thanks.

···

Walusiku J. Muyunda

Cell: +260967006614
Cell: +260971000614

Cell: +260953063387

"We have heaven to win and hell to shun, our lives testify better!"

Just load the script in your database and execute it with

SELECT * FROM delete_site_with_data(‘tPR9B5xETb’);

Regards,
Jason

···

Jason P. Pickering
email: jason.p.pickering@gmail.com
tel:+46764147049

Thank you. That works great.

···

Walusiku J. Muyunda

Cell: +260967006614
Cell: +260971000614

Cell: +260953063387

"We have heaven to win and hell to shun, our lives testify better!"