Problem creating the parent org unit through the API

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

guineaorgunit (335 Bytes)

···

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

···

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.

image

···

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Hi Sergio

You have a couple of options, you can switch to using “code”, which can basically be anything.

Another option is to simply generate the parent UIDs beforehand using /api/system/id?limit=X

···

http://dhis2.github.io/dhis2-docs/master/en/developer/html/ch01s39.html#d0e9612

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Hi Sergio,
The easier way to do this is to generate the UID prior to importing everything. You can do this pretty easily with the system with the following command

https://play.dhis2.org/demo/api/system/uid?limit=3

Or they can be generated externally pretty easily. Here is some R code , but I am sure there are ways to do this in other languages as well.

generateUID<-function(codeSize=11){

#Generate a random seed

runif(1)

allowedLetters<-c(LETTERS,letters)

allowedChars<-c(LETTERS,letters,0:9)

#First character must be a letter according to the DHIS2 spec

firstChar<-sample(allowedLetters,1)

otherChars<-sample(allowedChars,codeSize-1)

uid<-paste(c(firstChar,paste(otherChars,sep=“”,collapse=“”)),sep=“”,collapse=“”)

return(uid)}

The last option is to post these level by level and get the UID which was generated for the orgunit. The tricky part may be to get the first parent ID, but once you have that, it should be pretty easy.

Regards,

Jason

···

On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

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

I wanted to avoid the level by level option because I thought there has to be an easier way to do it. And there is!

I’ll go with the UID generation like both of you suggested me.

Thanks for your advice!

···

On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp


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

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

If you have your source data in postgresql, you can also use the following handy function to generate uids directly from the database:

CREATE OR REPLACE FUNCTION uid()

RETURNS text AS $$

SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’

FROM (random()*51)::int +1 for 1) ||

array_to_string(ARRAY(SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789’

FROM (random()*61)::int + 1 FOR 1)

FROM generate_series(1,10)), ‘’)

$$ LANGUAGE sql;

for example:

select *,uid() from myorgunits;

Will list your table together with some newly minted uids.

···

On 25 May 2016 at 13:01, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Sergio,
The easier way to do this is to generate the UID prior to importing everything. You can do this pretty easily with the system with the following command

https://play.dhis2.org/demo/api/system/uid?limit=3

Or they can be generated externally pretty easily. Here is some R code , but I am sure there are ways to do this in other languages as well.

generateUID<-function(codeSize=11){

#Generate a random seed

runif(1)

allowedLetters<-c(LETTERS,letters)

allowedChars<-c(LETTERS,letters,0:9)

#First character must be a letter according to the DHIS2 spec

firstChar<-sample(allowedLetters,1)

otherChars<-sample(allowedChars,codeSize-1)

uid<-paste(c(firstChar,paste(otherChars,sep=“”,collapse=“”)),sep=“”,collapse=“”)

return(uid)}

The last option is to post these level by level and get the UID which was generated for the orgunit. The tricky part may be to get the first parent ID, but once you have that, it should be pretty easy.

From my experience however, generating these prior to importing them is much easier and will allow you to edit things for instance, in your GIS software and then import them into DHIS2.

Regards,

Jason


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

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

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Yeah Bob, our source data is in postgresql so this is indeed very handy.

Thanks a lot!

···

2016-05-25 14:14 GMT+02:00 Bob Jolliffe bobjolliffe@gmail.com:

If you have your source data in postgresql, you can also use the following handy function to generate uids directly from the database:

CREATE OR REPLACE FUNCTION uid()

RETURNS text AS $$

SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’

FROM (random()*51)::int +1 for 1) ||

array_to_string(ARRAY(SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789’

FROM (random()*61)::int + 1 FOR 1)

FROM generate_series(1,10)), ‘’)

$$ LANGUAGE sql;

for example:

select *,uid() from myorgunits;

Will list your table together with some newly minted uids.

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

On 25 May 2016 at 13:01, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Sergio,
The easier way to do this is to generate the UID prior to importing everything. You can do this pretty easily with the system with the following command

https://play.dhis2.org/demo/api/system/uid?limit=3

Or they can be generated externally pretty easily. Here is some R code , but I am sure there are ways to do this in other languages as well.

generateUID<-function(codeSize=11){

#Generate a random seed

runif(1)

allowedLetters<-c(LETTERS,letters)

allowedChars<-c(LETTERS,letters,0:9)

#First character must be a letter according to the DHIS2 spec

firstChar<-sample(allowedLetters,1)

otherChars<-sample(allowedChars,codeSize-1)

uid<-paste(c(firstChar,paste(otherChars,sep=“”,collapse=“”)),sep=“”,collapse=“”)

return(uid)}

The last option is to post these level by level and get the UID which was generated for the orgunit. The tricky part may be to get the first parent ID, but once you have that, it should be pretty easy.

From my experience however, generating these prior to importing them is much easier and will allow you to edit things for instance, in your GIS software and then import them into DHIS2.

Regards,

Jason


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

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

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Thanks Bob, very useful indeed. I guess we should all have a closer look at what is shared here:
https://github.com/dhis2/dhis2-utils

Including your function:

https://github.com/dhis2/dhis2-utils/blob/master/resources/sql/uid.sql

···

On Wed, May 25, 2016 at 2:14 PM, Bob Jolliffe bobjolliffe@gmail.com wrote:

If you have your source data in postgresql, you can also use the following handy function to generate uids directly from the database:

CREATE OR REPLACE FUNCTION uid()

RETURNS text AS $$

SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’

FROM (random()*51)::int +1 for 1) ||

array_to_string(ARRAY(SELECT substring(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789’

FROM (random()*61)::int + 1 FOR 1)

FROM generate_series(1,10)), ‘’)

$$ LANGUAGE sql;

for example:

select *,uid() from myorgunits;

Will list your table together with some newly minted uids.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

On 25 May 2016 at 13:01, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Sergio,
The easier way to do this is to generate the UID prior to importing everything. You can do this pretty easily with the system with the following command

https://play.dhis2.org/demo/api/system/uid?limit=3

Or they can be generated externally pretty easily. Here is some R code , but I am sure there are ways to do this in other languages as well.

generateUID<-function(codeSize=11){

#Generate a random seed

runif(1)

allowedLetters<-c(LETTERS,letters)

allowedChars<-c(LETTERS,letters,0:9)

#First character must be a letter according to the DHIS2 spec

firstChar<-sample(allowedLetters,1)

otherChars<-sample(allowedChars,codeSize-1)

uid<-paste(c(firstChar,paste(otherChars,sep=“”,collapse=“”)),sep=“”,collapse=“”)

return(uid)}

The last option is to post these level by level and get the UID which was generated for the orgunit. The tricky part may be to get the first parent ID, but once you have that, it should be pretty easy.

From my experience however, generating these prior to importing them is much easier and will allow you to edit things for instance, in your GIS software and then import them into DHIS2.

Regards,

Jason


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Thanks Morten, yes, we were trying to create a new root and we were missing that step.

My question now is: In the “parent” object included in “organisationUnits”, is it possible to swap the attribute “id” to “name” (or something you know when you are creating the parents)? Otherwise, how can be done the import of a whole org unit hierarchy (in a single json) when you don’t know the “id” of the “parents”?

I attached an image pointing the part of the json I’m talking about.


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

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

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62

2016-05-25 13:13 GMT+02:00 Morten Olav Hansen morten@dhis2.org:

Hi Sergio

So you are creating a new root? Could it be that your user is attached to a different org unit, and so the problem is that you can’t see them?

Maybe you could verify in the database, or using the web-api? /api/organisationUnits.json?filter=name:like:abc

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Wed, May 25, 2016 at 6:06 PM, Sergio Valenzuela sergio.valenzuela@ehas.org wrote:

Hello devs,

We are trying to create a whole org unit hierarchy through the new API resource /api/23/metadata .

During the process, we realized there should be some kind of problem when we tried to create the parent org unit (the parent of the whole hierarchy), because even If the answer from the server is 200 OK once we sent the POST and with a GET we can verify that the org units are created successfully, no org units are appearing on Maintenance App. We are using the same version and build as in demo server (version 2.23 and build 22969).
We tried the same in demo server with the same result.

I attached our JSON and the url we were doing the POST request:

Tell me If I’m doing something wrong here or If this issue was already reported.

Best Regards!

Sergio Valenzuela
Fundación EHAS
Telemedicina para países en desarrollo -www.ehas.org

E.T.S.I. de Telecomunicación A.101-9L. Ciudad Universitaria 30, 28040 Madrid - España

Tlfno. (+34) 91 488 87 41: (+34) 687 67 17 62


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Knut Staring

Dept. of Informatics, University of Oslo

Norway: +4791880522

Skype: knutstar

http://dhis2.org