dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40355
Re: Removing Organization Units
Hi Gerald,
Removal of orgunits with associated reports or charts is non trivial, due
to the use of the "sort_order" in these resources. It will cause a null
pointer exception if you just delete the orgunit.
I have added two functions to the dhis2-utils repo, which handle the
deletion and merging of orgunits.
To delete a site with data , you can try the following postgresql function.
https://github.com/dhis2/dhis2-utils/blob/master/resources/sql/delete_site_with_data.sql
This function accepts the UID of the organisation unit to delete.
Obviously, this function is provided without any warranty. You should
certainly make a backup of the database prior to executing it.
This function will handle the removal of orgunits (with no children) and
should handle cleaning up the various report associations as well.
Be sure to clear your server cache afterwards.
Best regards,
Jason
On Thu, Oct 1, 2015, 18:49 Bob Jolliffe <bobjolliffe@xxxxxxxxx> wrote:
> Gerald you would need to do this with an sql delete command. Before
> you do you should be 100% sure that you do really want to delete the
> data - maybe make a backup first.
>
> You need to find the primary key (organisationunitid) of the orgunit
> you want to delete. Say it is 5677 Then:
>
> DELETE FROM datavalue where sourceid like 5677;
>
> If you have a few then something like:
>
> -- examples only!
> DELETE FROM datavalue where sourceid in (5677, 5674, 3456);
>
> If you have many then put them in a temporary orgunit group and make a
> fancier query.
>
> Note you might still get the odd error when deleting the orgunit if
> your orgunits are being used in charts and the like. You'll have to
> address these one at a time.
>
> On 1 October 2015 at 17:39, gerald thomas <gerald17006@xxxxxxxxx> wrote:
> > Dear Dapo,
> > What is the command to remove those data from the database as per
> > organisation unit?
> > Please help me.
> >
> > Regards,
> > Gerald
> >
> > On Oct 1, 2015 16:16, "Dapo Adejumo" <dapsyjorge@xxxxxxxxx> wrote:
> >>
> >> Hi Gerald,
> >> What error are you getting?
> >> If you have data associated with these org units, you will not be able
> to
> >> remove them until you delete the data in the database (even if you have
> >> removed the datasets).
> >>
> >> ………………………………………
> >> Regards,
> >> Dapo Adejumo
> >> +2348033683677
> >> Skype : dapojorge
> >>
> >> ----- Original Message -----
> >> From: "gerald thomas" <gerald17006@xxxxxxxxx>
> >> To: "dhis2-users" <dhis2-users@xxxxxxxxxxxxxxxxxxx>, "dhis2-devs"
> >> <dhis2-devs@xxxxxxxxxxxxxxxxxxx>
> >> Sent: Thursday, October 1, 2015 5:10:25 PM
> >> Subject: [Dhis2-devs] Removing Organization Units
> >>
> >> Dear All,
> >> I am trying to remove Organisation Units from DHIS2 versions 2.18 and
> >> 2.20 but i am getting error.
> >>
> >> But i had already removed the datasets associated with these
> >> Organisation Units but i still can't remove them.
> >>
> >> Please can someone help.
> >>
> >> --
> >> Regards,
> >>
> >> Gerald
> >>
> >> _______________________________________________
> >> 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
> >
> >
> > _______________________________________________
> > 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
> >
>
> _______________________________________________
> 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
>
Follow ups
References