← Back to team overview

dhis2-devs team mailing list archive

Re: [Dhis2-users] In DHIS 2.27 Issues with deleting organisation unit

 

Hi Joseph
Thanks for sharing the script.

One thing to watch out for is the reordering of components of analytical
objects. You can see this here
<https://github.com/dhis2/dhis2-utils/blob/master/resources/sql/delete_orgunit_with_data.sql#L64-L71>
in
the script I linked to in the earlier mail. If you delete an organisation
unit from say a chart, without reordering the other organisation units, it
will lead to an error when trying to load that object after the
organisation unit has been deleted.

Regards,
Jason


On Fri, Dec 15, 2017 at 9:39 AM, Joseph Chingalo <profschingalo@xxxxxxxxx>
wrote:

> Hello Jhansi Reddy Karee and All,
>
> I have work around for this by creating  SQL view  procedure for deleting
> an organisation unit in dhis 2 instance .
>
> Just kindly find attached SQL file with all procedure functions for
> delete an Organisation unit.
>
> *Steps on how to use this*
>
> *Step 1:*
>
> All you need to do edit variable for storage of all backup files as csv in
> case you want to rollback all deleted data.
> Below is variable to changes on line number 6 with path to directory for
> backup of deleted data, for instance on my case is "/tmp/data" but it must
> have readable and writable.
> " temp_dir VARCHAR := '/tmp/data'; "
>
> *Step 2:*
>
> Apply this sql file into your database
>
> *Step 3:*
>
> Create sql view and excute it.
> For instance if zs9X8YYBOnK is uid for organisation unit to be deleted
> then SQL view will be
> SELECT deleteOrganisationUnit('zs9X8YYBOnK');
>
> *Hopes might help you.*
>
>
>
>
> On Fri, Dec 15, 2017 at 10:16 AM, Jhansi Reddy Karee <
> jhansirk@xxxxxxxxxxxxxxxx> wrote:
>
>> Thanks Jason,
>>
>> Since we just have data values for the organisation units (which should
>> be deleted), we are able to remove them after clearing the data associated
>> with them using /api/maintenance/dataPruning/organisationUnits API.
>>
>> Thanks,
>> Jhansi
>>
>> On Fri, Dec 15, 2017 at 11:51 AM, Jason Pickering <
>> jason.p.pickering@xxxxxxxxx> wrote:
>>
>>> It might work for you, but I am not 100% sure if that API endpoint will
>>> clear out everything. As you can  see from the SQL function, orgunits may
>>> also have other dependencies, like pivots, charts, user associations, etc.
>>> The deletion handler for orgunits may refuse to remove it,  if the object
>>> is associated with other objects.
>>>
>>> It might work in your case, but may not.
>>>
>>> Good luck,
>>> Jason
>>>
>>>
>>> On Fri, Dec 15, 2017 at 7:14 AM, Jhansi Reddy Karee <
>>> jhansirk@xxxxxxxxxxxxxxxx> wrote:
>>>
>>>> Thanks for the quick reply Jason,
>>>>
>>>> In DHIS documentation
>>>> <https://docs.dhis2.org/2.27/en/developer/html/webapi_maintenance.html>,
>>>> we came across a WEB API which can clear all the data of the organisation
>>>> unit.
>>>>
>>>> /api/26/maintenance/dataPruning/organisationUnits/<org-unit-id>
>>>>
>>>> API Details: Data pruning will remove complete data set registrations,
>>>> data approvals, data value audits and data values, in this case of an
>>>> organisation unit.
>>>>
>>>> We are expecting that this API will clear all the data of the given
>>>> organisation unit and any data/approvals of its parent organisation units
>>>> will be untouched. Is our expectation correct?
>>>>
>>>> Do you see any problem with deleting data for the organisation unit
>>>> using this API.
>>>>
>>>> Thanks,
>>>> Jhansi
>>>>
>>>> On Thu, Dec 14, 2017 at 9:12 PM, Jason Pickering <
>>>> jason.p.pickering@xxxxxxxxx> wrote:
>>>>
>>>>> Hi Jhansi,
>>>>> You will also need to get rid of the data in the data value audit
>>>>> table.
>>>>>
>>>>> Here is an SQL function which might work for you.
>>>>>
>>>>> https://github.com/dhis2/dhis2-utils/blob/master/resources/s
>>>>> ql/delete_orgunit_with_data.sql
>>>>>
>>>>> Regards,
>>>>> Jason
>>>>>
>>>>>
>>>>> On Thu, Dec 14, 2017 at 2:49 PM, Jhansi Reddy Karee <
>>>>> jhansirk@xxxxxxxxxxxxxxxx> wrote:
>>>>>
>>>>>> Hello Team,
>>>>>>
>>>>>>
>>>>>> In DHIS 2.27, we are not able to delete an organisation unit after
>>>>>> deleting all the data associated to it.
>>>>>>
>>>>>>
>>>>>> Following are the steps we have followed to do this:
>>>>>>
>>>>>>    -
>>>>>>
>>>>>>    Delete all the data associated to the organisation unit
>>>>>>    -
>>>>>>
>>>>>>    In Data administration app, under maintenance, we have performed
>>>>>>    maintenance over “Permanently remove soft deleted data values”.
>>>>>>    -
>>>>>>
>>>>>>    Tried deleting the organisation unit. But, we are getting the
>>>>>>    following error: Could not delete due to association with another object:
>>>>>>    DataValueAudit
>>>>>>
>>>>>>
>>>>>> Please let us know if we have missed anything.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Jhansi
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Mailing list: https://launchpad.net/~dhis2-devs
>>>>>> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
>>>>>> Unsubscribe : https://launchpad.net/~dhis2-devs
>>>>>> More help   : https://help.launchpad.net/ListHelp
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Jason P. Pickering
>>>>> email: jason.p.pickering@xxxxxxxxx
>>>>> tel:+46764147049 <076-414%2070%2049>
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Jason P. Pickering
>>> email: jason.p.pickering@xxxxxxxxx
>>> tel:+46764147049 <+46%2076%20414%2070%2049>
>>>
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~dhis2-users
>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~dhis2-users
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>
>
> --
>
>
> *Joseph Philibert Chingalo*
> *+255 687 168 637 <+255%20687%20168%20637>*
> *+255 718 922 311 <+255%20718%20922%20311>*
> *Skype : josephchingalowebsite : http://hisptanzania.org/
> <http://hisptanzania.org/>*
>
>
>
>


-- 
Jason P. Pickering
email: jason.p.pickering@xxxxxxxxx
tel:+46764147049

References