dhis2-users team mailing list archive
-
dhis2-users team
-
Mailing list archive
-
Message #15193
Posting Metadata in dhis2.
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.
Follow ups