← Back to team overview

dhis2-users team mailing list archive

Re: Posting Metadata in dhis2.

 

This is super, I will try and work around that.

Thank you.

==========================
Isaiah Nyabuto
+254729572616
Bsc. Health Records Management and Informatics

On Feb 15, 2018 17:10, "Knut Staring" <knutst@xxxxxxxxx> wrote:

> Everything done from the user interface is done through the API, so yes.
> The API also gives you more flexibility to filter etc. The manual describes
> this.
>
> https://docs.dhis2.org/master/en/developer/html/webapi_metadata_crud.html
> https://docs.dhis2.org/master/en/developer/html/webapi_
> metadata_export.html
> https://docs.dhis2.org/master/en/developer/html/webapi_
> metadata_synchronization.html
>
>
> On Thu, Feb 15, 2018 at 8:56 AM, Isaiah Nyabuto <isaiahnyabuto@xxxxxxxxx>
> wrote:
>
>>
>> Hi Knut,
>>
>> Yes. And is it possible to do that APIs?
>>
>> Thank you.
>>
>>
>> ==========================
>> Isaiah Nyabuto
>> +254729572616 <+254%20729%20572616>
>> Bsc. Health Records Management and Informatics
>>
>> On Feb 15, 2018 16:29, "Knut Staring" <knutst@xxxxxxxxx> wrote:
>>
>>> Hi Isaiah,
>>>
>>> When you say "extract", you mean you want to take metadata from one
>>> instance of DHIS2 and import to another one? That can be done through the
>>> user interface as described in the user manual:
>>> https://docs.dhis2.org/master/en/user/html/import_export.html
>>> https://play.dhis2.org/2.28/dhis-web-importexport/index.action
>>>
>>> You can also load metadata from CSV:
>>> https://docs.dhis2.org/master/en/developer/html/webapi_csv_m
>>> etadata_import.html
>>>
>>> On Thu, Feb 15, 2018 at 7:33 AM, Isaiah Nyabuto <isaiahnyabuto@xxxxxxxxx
>>> > wrote:
>>>
>>>> Hi Jason,
>>>>
>>>> Thank you. I am going to look into that keenly.
>>>> And If I may ask, is there a way I can extract dhis2 metadata that can
>>>> be imported directly or with minimal transformations?
>>>>
>>>> This will be helpful. Thank you.
>>>>
>>>> ==========================
>>>> Isaiah Nyabuto
>>>> +254729572616 <+254%20729%20572616>
>>>> Bsc. Health Records Management and Informatics
>>>>
>>>> On Feb 15, 2018 15:16, "Jason Pickering" <jason.p.pickering@xxxxxxxxx>
>>>> wrote:
>>>>
>>>>> Hi Isaiah,
>>>>>
>>>>> You have
>>>>>
>>>>>
>>>>> "parent":"vpiZlB5cdK7"
>>>>>
>>>>>
>>>>> It should be
>>>>>
>>>>> parent":{"id":"vpiZlB5cdK7"}}
>>>>>
>>>>> Be sure your JSON structure is exactly as it should be, otherwise, you
>>>>> will get those kinds of errors. Study the example here
>>>>> <https://raw.githubusercontent.com/jason-p-pickering/dhis2-data-munging/master/ous/ous.json>
>>>>> .
>>>>>
>>>>> Regards,
>>>>> Jason
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Feb 15, 2018 at 1:07 PM, Isaiah Nyabuto <
>>>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>>>
>>>>>> Thank you for the tip. It still doesn't work.
>>>>>> what does this error mean?
>>>>>>
>>>>>> httr::content(r, "text")
>>>>>>
>>>>>> [1] "{\"httpStatus\":\"Internal Server Error\",\"httpStatusCode\":500
>>>>>> ,\"status\":\"ERROR\",\"message\":\"Can not instantiate value of
>>>>>> type [simple type, class org.hisp.dhis.organisationunit.OrganisationUnit]
>>>>>> from String value ('It7fWcKbcZX'); no single-String constructor/factory
>>>>>> method\\n at [Source: org.apache.catalina.connector.
>>>>>> CoyoteInputStream@1efec811; line: 1, column: 73] (through reference
>>>>>> chain: org.hisp.dhis.organisationunit.OrganisationUnit[\\\"parent\\\
>>>>>> "])\"}"
>>>>>>
>>>>>> Anyone?
>>>>>>
>>>>>> Thank you.
>>>>>> ==========================
>>>>>> Isaiah Nyabuto
>>>>>> +254729572616 <+254%20729%20572616>
>>>>>> Bsc. Health Records Management and Informatics
>>>>>>
>>>>>> On Feb 15, 2018 13:14, "Jason Pickering" <jason.p.pickering@xxxxxxxxx>
>>>>>> wrote:
>>>>>>
>>>>>> All of your fields must have exactly the correct names:
>>>>>>
>>>>>> shortname -> shortName
>>>>>> featuretype-> featureType
>>>>>>
>>>>>> Keep hacking at it! You will get there!
>>>>>>
>>>>>> Regards,
>>>>>> Jason
>>>>>>
>>>>>>
>>>>>> On Thu, Feb 15, 2018 at 11:08 AM, Isaiah Nyabuto <
>>>>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>>>>
>>>>>>> Hi Jason,
>>>>>>>
>>>>>>> Here is some bit of my post data.
>>>>>>>
>>>>>>> {"organisationUnits":[{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5","code":"16925","parent":"vpiZlB5cdK7","shortname":"Wikithuki Dispensary","description":"","comment":"","featuretype":"POINT","coordinates":"[37.95263,-0.77819]","url":""},{"name":"Gemifa Medical Clinic","uid":"Z7Lf1n3Fcpi","code":"22907","parent":"mEZBjj4fLBT","shortname":"Gemifa","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.391914,0.059575]","url":""},{"name":"Olympus Medical Clinic","uid":"NAbQdHuaJFK","code":"22906","parent":"PeEcMfBchbr","shortname":"Olympus","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.3994,0.059575]","url":""},{"name":"Masaba Community Health Unit","uid":"tYwHeLSnHyb","code":"600616","parent":"QR2K4k8VKF1","shortname":"Masaba CHU","description":"Community Unit","comment":"","featuretype":"NONE","coordinates":"[34.46411,0.19358]","url":""},{"name":"Gatunga Health Centre","uid":"cmay4WXRmhA","code":"12034","parent":
>>>>>>>
>>>>>>>
>>>>>>> After changing the "uid" to "id",  still it doesn't work.
>>>>>>>
>>>>>>> Thank you
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Feb 15, 2018 at 12:14 PM, Jason Pickering <
>>>>>>> jason.p.pickering@xxxxxxxxx> wrote:
>>>>>>>
>>>>>>>> Hi Isaiah,
>>>>>>>>
>>>>>>>> Post a bit of your JSON here from  toJSON(list(organisationUnits=new_org),
>>>>>>>> auto_unbox = TRUE)
>>>>>>>>
>>>>>>>> One other problem I noticed as well is this
>>>>>>>>
>>>>>>>> [{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5"
>>>>>>>>
>>>>>>>>
>>>>>>>> It should be
>>>>>>>>
>>>>>>>> [{"name":"Wikithuki Dispensary","id":"Bc371uxfYD5"
>>>>>>>>
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Jason
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Feb 15, 2018 at 10:01 AM, Isaiah Nyabuto <
>>>>>>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>>>>>>
>>>>>>>>> Hi Jason,
>>>>>>>>>
>>>>>>>>> I get an internal server error code: 500, after trying that. Here
>>>>>>>>> is the response;
>>>>>>>>>
>>>>>>>>> httr::content(r, "text")[1] "{\"httpStatus\":\"Internal Server Error\",\"httpStatusCode\":500,\"status\":\"ERROR\",\"message\":\"Can not instantiate value of type [simple type, class org.hisp.dhis.organisationunit.OrganisationUnit] from String value ('It7fWcKbcZX'); no single-String constructor/factory method\\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1efec811; line: 1, column: 73] (through reference chain: org.hisp.dhis.organisationunit.OrganisationUnit[\\\"parent\\\"])\"}"
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thank you.
>>>>>>>>>
>>>>>>>>> On Thu, Feb 15, 2018 at 10:36 AM, Jason Pickering <
>>>>>>>>> jason.p.pickering@xxxxxxxxx> wrote:
>>>>>>>>>
>>>>>>>>>> Hi Isiah,
>>>>>>>>>>
>>>>>>>>>> The reason for it not working (at least at first glance) is that
>>>>>>>>>> you are posing to the /api/metadata endpoint. Thus, you need to tell the
>>>>>>>>>> server what you are trying to import. In this case, its organisation units.
>>>>>>>>>>
>>>>>>>>>> I think changing this to
>>>>>>>>>>
>>>>>>>>>>   r <- POST(url, authenticate(dest.user, dest.pass),
>>>>>>>>>>             body = toJSON(list(organisationUnits=new_org),
>>>>>>>>>> auto_unbox = TRUE),
>>>>>>>>>>             content_type_json())
>>>>>>>>>>
>>>>>>>>>> should work.
>>>>>>>>>>
>>>>>>>>>> The example works because the file
>>>>>>>>>> <https://raw.githubusercontent.com/jason-p-pickering/dhis2-data-munging/master/ous/ous.json>
>>>>>>>>>> looks like this:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> {"created":"2016-08-10","organisationUnits":[{"id":"u6yjgvIMzKn",...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hope this helps and best regards,
>>>>>>>>>>
>>>>>>>>>> Jason
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, Feb 15, 2018 at 6:34 AM, Isaiah Nyabuto <
>>>>>>>>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Dear Jason and Dhis2 Community,
>>>>>>>>>>>
>>>>>>>>>>> I am following your guide on bootstrapping
>>>>>>>>>>> <https://github.com/jason-p-pickering/dhis2-data-munging/blob/master/bootstrap/bootstrap.Rmd>
>>>>>>>>>>>  dhis2 with R while trying to import metadata using the API.
>>>>>>>>>>>
>>>>>>>>>>> I do not understand why my metadata is not imported. Here are my
>>>>>>>>>>> steps, any help will be appreciated.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> head(org)                          name         uid   code      parent             shortname
>>>>>>>>>>> 1         Wikithuki Dispensary Bc371uxfYD5  16925 vpiZlB5cdK7  Wikithuki Dispensary
>>>>>>>>>>> 2        Gemifa Medical Clinic Z7Lf1n3Fcpi  22907 mEZBjj4fLBT                Gemifa
>>>>>>>>>>> 3       Olympus Medical Clinic NAbQdHuaJFK  22906 PeEcMfBchbr               Olympus
>>>>>>>>>>> 4 Masaba Community Health Unit tYwHeLSnHyb 600616 QR2K4k8VKF1            Masaba CHU
>>>>>>>>>>> 5        Gatunga Health Centre cmay4WXRmhA  12034 IcAegRcGuV6 Gatunga Health Centre
>>>>>>>>>>> 6         Cfw Kimangaru Clinic E52UsoBxJVS  11966 vEAFtHnPDrX  CFW Kimangaru Clinic
>>>>>>>>>>>      description openingdate closedate comment featuretype          coordinates url
>>>>>>>>>>> 1                         NA        NA               POINT  [37.95263,-0.77819]
>>>>>>>>>>> 2         Clinic          NA        NA                NONE [34.391914,0.059575]
>>>>>>>>>>> 3         Clinic          NA        NA                NONE   [34.3994,0.059575]
>>>>>>>>>>> 4 Community Unit          NA        NA                NONE   [34.46411,0.19358]
>>>>>>>>>>> 5                         NA        NA               POINT   [37.9423,-0.29656]
>>>>>>>>>>> 6                         NA        NA               POINT  [37.53009,-0.54506]
>>>>>>>>>>>   contactperson address email phonenumber
>>>>>>>>>>> 1            NA      NA    NA          NA
>>>>>>>>>>> 2            NA      NA    NA          NA
>>>>>>>>>>> 3            NA      NA    NA          NA
>>>>>>>>>>> 4            NA      NA    NA          NA
>>>>>>>>>>> 5            NA      NA    NA          NA
>>>>>>>>>>> 6            NA      NA    NA          NA
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I followed the following steps to prepare my df for import.
>>>>>>>>>>> 1. Removed all the NAs  and columns with entire NAs.
>>>>>>>>>>>
>>>>>>>>>>> head(new_org)                          name         uid   code      parent             shortname
>>>>>>>>>>> 1         Wikithuki Dispensary Bc371uxfYD5  16925 vpiZlB5cdK7  Wikithuki Dispensary
>>>>>>>>>>> 2        Gemifa Medical Clinic Z7Lf1n3Fcpi  22907 mEZBjj4fLBT                Gemifa
>>>>>>>>>>> 3       Olympus Medical Clinic NAbQdHuaJFK  22906 PeEcMfBchbr               Olympus
>>>>>>>>>>> 4 Masaba Community Health Unit tYwHeLSnHyb 600616 QR2K4k8VKF1            Masaba CHU
>>>>>>>>>>> 5        Gatunga Health Centre cmay4WXRmhA  12034 IcAegRcGuV6 Gatunga Health Centre
>>>>>>>>>>> 6         Cfw Kimangaru Clinic E52UsoBxJVS  11966 vEAFtHnPDrX  CFW Kimangaru Clinic
>>>>>>>>>>>      description comment featuretype          coordinates url
>>>>>>>>>>> 1                              POINT  [37.95263,-0.77819]
>>>>>>>>>>> 2         Clinic                NONE [34.391914,0.059575]
>>>>>>>>>>> 3         Clinic                NONE   [34.3994,0.059575]
>>>>>>>>>>> 4 Community Unit                NONE   [34.46411,0.19358]
>>>>>>>>>>> 5                              POINT   [37.9423,-0.29656]
>>>>>>>>>>> 6                              POINT  [37.53009,-0.54506]
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> 3. Then post the data as follows.
>>>>>>>>>>>
>>>>>>>>>>> dest.url <- "http://localhost/dhis/";
>>>>>>>>>>> url <- paste0(dest.url, "api/metadata?importStrategy=C
>>>>>>>>>>> REATE&atomicMode=NONE")
>>>>>>>>>>>   r <- POST(url, authenticate(dest.user, dest.pass),
>>>>>>>>>>>             body = toJSON(new_org, auto_unbox = TRUE),
>>>>>>>>>>>             content_type_json())
>>>>>>>>>>>   assertthat::assert_that(r$status_code==200)
>>>>>>>>>>>
>>>>>>>>>>> 4. The body looks like.
>>>>>>>>>>>
>>>>>>>>>>> jsonlite::toJSON(me, auto_unbox = TRUE)[{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5","code":"16925","parent":"vpiZlB5cdK7","shortname":"Wikithuki Dispensary","description":"","comment":"","featuretype":"POINT","coordinates":"[37.95263,-0.77819]","url":""},{"name":"Gemifa Medical Clinic","uid":"Z7Lf1n3Fcpi","code":"22907","parent":"mEZBjj4fLBT","shortname":"Gemifa","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.391914,0.059575]","url":""},{"name":"Olympus Medical Clinic","uid":"NAbQdHuaJFK","code":"22906","parent":"PeEcMfBchbr","shortname":"Olympus","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.3994,0.059575]","url":""},{"name":"Masaba Community Health Unit","uid":"tYwHeLSnHyb","code":"600616","parent":"QR2K4k8VKF1","shortname":"Masaba CHU","description":"Community Unit","comment":"","featuretype":"NONE","coordinates":"[34.46411,0.19358]","url":""},{"name":"Gatunga Health Centre","uid":"cmay4WXRmhA","code":"12034","parent":"IcAegRcGuV6","shortname":"Gatunga Health Centre","description":"","comment":"","featuretype":"POINT","coordinates":"[37.9423,-0.29656]","url":""},{"name":"Cfw Kimangaru Clinic","uid":"E52UsoBxJVS","code":"11966","parent":"vEAFtHnPDrX","shortname":"CFW Kimangaru Clinic","description":"","comment":"","featuretype":"POINT","coordinates":"[37.53009,-0.54506]","url":""}]
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> What could be the problem there? I get status 200 and still it
>>>>>>>>>>> doesn't import.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Thank you
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>> --------------------
>>>>>>>>>>> Isaiah Nyabuto
>>>>>>>>>>> +254 729 572 616
>>>>>>>>>>> Bsc. Health Records Management & Informatics, JKUAT.
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> Jason P. Pickering
>>>>>>>>>> email: jason.p.pickering@xxxxxxxxx
>>>>>>>>>> tel:+46764147049 <076-414%2070%2049>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> ------------------------------------------------------------
>>>>>>>>> --------------------
>>>>>>>>> Isaiah Nyabuto
>>>>>>>>> +254 729 572 616
>>>>>>>>> Bsc. Health Records Management & Informatics, JKUAT.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Jason P. Pickering
>>>>>>>> email: jason.p.pickering@xxxxxxxxx
>>>>>>>> tel:+46764147049 <076-414%2070%2049>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> ------------------------------------------------------------
>>>>>>> --------------------
>>>>>>> Isaiah Nyabuto
>>>>>>> +254 729 572 616
>>>>>>> Bsc. Health Records Management & Informatics, JKUAT.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> 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
>>>>
>>>>
>>>
>>>
>>> --
>>> Knut Staring
>>>
>>> Department of Information, Evidence and Research
>>> World Health Organization, Geneva, Switzerland
>>> Office: +41 22 791 3683 <+41%2022%20791%2036%2083> Mob1: +33 6 4434 2931
>>> <+33%206%2044%2034%2029%2031> Mob2: +47 9188 0522
>>> Skype:     knutstar
>>>
>>
>
>
> --
> Knut Staring
>
> Department of Information, Evidence and Research
> World Health Organization, Geneva, Switzerland
> Office: +41 22 791 3683 Mob1: +33 6 4434 2931 Mob2: +47 9188 0522
> Skype:     knutstar
>

References