dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #45149
Re: Problem creating the parent org unit through the API
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
On Wed, May 25, 2016 at 1:54 PM, Sergio Valenzuela <
sergio.valenzuela@xxxxxxxx> 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
> <http://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@xxxxxxxxx>:
>
>> 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@xxxxxxxx> 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:
>>>
>>> - https://play.dhis2.org/demo/api/23/metadata
>>> <https://www.google.com/url?q=https%3A%2F%2Fplay.dhis2.org%2Fdemo%2Fapi%2F23%2Fmetadata&sa=D&sntz=1&usg=AFQjCNFEcEvpUIBy7DQX7KNTUvGRw7nObw>
>>>
>>> Besides, we tried to create the parent org unit of the whole hierarchy
>>> through the Maintenance interface with the same result. Apparently, it is
>>> created but not shown after on Maintenance App. (We made a GET to
>>> http://localhost:8080/api/metadata?assumeTrue=false&organisationUnits=true
>>> and we verified that the org unit was created)
>>>
>>> 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
>>> <http://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@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
>
>
--
Jason P. Pickering
email: jason.p.pickering@xxxxxxxxx
tel:+46764147049
Follow ups
References