1
by Bob Jolliffe
init |
1 |
package require TclCurl
|
2 |
||
3 |
set dw_user admin
|
|
4 |
set dw_passwd district
|
|
5 |
set hmis_user bobj
|
|
4
by Bob Jolliffe
added district hospital fix |
6 |
set hmis_passwd mZ1l1kaz1
|
1
by Bob Jolliffe
init |
7 |
|
8 |
#set dw http://localhost/datawarehouse
|
|
9 |
set dw http://$dw_user:$dw_passwd@localhost/datawarehouse |
|
10 |
set hmis http://$hmis_user:$hmis_passwd@localhost/hmis |
|
11 |
||
12 |
proc ignoreData {data} { |
|
13 |
}
|
|
14 |
||
15 |
file delete -force export.zip |
|
16 |
||
17 |
# Act 1 : exporting orgunits from hmis
|
|
18 |
# TODO: need to trap some errors
|
|
19 |
set hmis_hnd [curl::init] |
|
20 |
$hmis_hnd configure -url $hmis/dhis-web-importexport/exportMetaData.action |
|
21 |
$hmis_hnd configure -headervar header |
|
22 |
$hmis_hnd configure -postfields "exportFormat=DXF&organisationUnits=true&organisationUnitGroups=true&organisationUnitGroupSets=true&organisationUnitLevels=true" |
|
23 |
$hmis_hnd configure -file export.zip |
|
24 |
if [catch {set res [$hmis_hnd perform ]} err] { |
|
25 |
puts stderr [curl::easystrerror $err] |
|
26 |
exit 1 |
|
27 |
}
|
|
28 |
||
29 |
$hmis_hnd cleanup |
|
30 |
puts stderr "Retrieved orgunits from hmis" |
|
31 |
||
32 |
# Got that. Now on to part 2
|
|
33 |
||
34 |
# Act 2 : importing orgunits to datawarehouse
|
|
35 |
# Act 2 Scene 1 - we have to set the import type :-(
|
|
36 |
set dw_hnd [curl::init] |
|
37 |
||
38 |
$dw_hnd configure -cookiefile "" |
|
39 |
$dw_hnd configure -writeproc ignoreData |
|
40 |
$dw_hnd configure -followlocation 1 |
|
41 |
||
42 |
$dw_hnd configure -url "$dw/dhis-web-importexport/setImportFormat.action?importFormat=DXF" |
|
43 |
set res [$dw_hnd perform ] |
|
44 |
if {$res} { |
|
45 |
puts stderr [curl::easystrerror $res] |
|
46 |
exit 1 |
|
47 |
}
|
|
48 |
puts stderr "set importFormat to DXF" |
|
49 |
||
50 |
# Act 2 Scene 2 - we can import the metadata :-)
|
|
51 |
$dw_hnd configure -httppost [list name "type" contents "IMPORT" ] |
|
52 |
$dw_hnd configure -httppost [list name "incomingRecords" contents "NEW_AND_UPDATES"] |
|
53 |
$dw_hnd configure -httppost [list name "upload" file "export.zip" contenttype "application/zip"] |
|
54 |
$dw_hnd configure -httppost [list name "skipCheckMatching" contents "false"] |
|
55 |
$dw_hnd configure -httppost [list name "dataValues" contents "false"] |
|
56 |
$dw_hnd configure -url $dw/dhis-web-importexport/import.action |
|
57 |
||
58 |
set res [$dw_hnd perform ] |
|
59 |
if {$res} { |
|
60 |
puts stderr [curl::easystrerror $res] |
|
61 |
exit 1 |
|
62 |
}
|
|
63 |
||
64 |
puts stderr "Export file sent to datawarehouse" |
|
65 |
||
66 |
# Act 2 Scene 3 - monitor the status :-)
|
|
67 |
||
68 |
# should finish ok, but if not, self-destruct after 60s
|
|
69 |
after 60000 {exit 1} |
|
70 |
||
71 |
proc checkStatus {} { |
|
72 |
$::dw_hnd configure -url $::dw/dhis-web-importexport/getImportStatus.action |
|
73 |
$::dw_hnd configure -bodyvar data |
|
74 |
$::dw_hnd perform |
|
75 |
if {[regexp {statusMessage\>([^\<]*)} $data match msg]} { |
|
76 |
puts stderr $msg |
|
77 |
if [regexp completed|failed $msg] { |
|
78 |
set ::done 1 |
|
79 |
}
|
|
80 |
}
|
|
81 |
after 500 checkStatus |
|
82 |
}
|
|
83 |
||
84 |
after 500 checkStatus |
|
85 |
||
86 |
vwait done
|
|
87 |
puts stderr "done" |