dhis2 2.2.1 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -6
- data/dhis2.gemspec +2 -0
- data/lib/dhis2/api/attribute.rb +6 -0
- data/lib/dhis2/api/base.rb +5 -0
- data/lib/dhis2/api/data_element.rb +10 -10
- data/lib/dhis2/api/data_element_group.rb +10 -1
- data/lib/dhis2/api/data_set.rb +7 -2
- data/lib/dhis2/api/data_value_set.rb +43 -12
- data/lib/dhis2/api/organisation_unit.rb +1 -0
- data/lib/dhis2/api/organisation_unit_group.rb +19 -0
- data/lib/dhis2/api/system_info.rb +11 -0
- data/lib/dhis2/pager.rb +10 -7
- data/lib/dhis2/version.rb +1 -1
- data/lib/dhis2.rb +7 -6
- metadata +38 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 367a235ae4138cbe459be2b16a1c5766a74795b7
|
4
|
+
data.tar.gz: ead76712bed0f67df5c4896820defe3f94f5e5da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9466e838c544703902d2e2ed95de69618a1c648e88deb899dcacc22abb4f20cc094b0404fc16f9044bad58522e1db7826d896d8287e565496012ba752a15931e
|
7
|
+
data.tar.gz: 69cb9a93ccf9a28b7f99919ce93d183d6a98875f2643374e487a4be0e3de75a24fed52832a3fe6e37912715c0d2910424e60b78e4961a78d9630617961c2f1b2
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ The functionalities are available as a module. First thing you need to do is to
|
|
29
29
|
|
30
30
|
* Global configuration (to call a single Dhis2 instance):
|
31
31
|
|
32
|
-
```ruby
|
32
|
+
```ruby
|
33
33
|
Dhis2.configure do |config|
|
34
34
|
config.url = "https://play.dhis2.org/demo"
|
35
35
|
config.user = "admin"
|
@@ -45,8 +45,8 @@ The functionalities are available as a module. First thing you need to do is to
|
|
45
45
|
```
|
46
46
|
|
47
47
|
* Local configuration: (in case you need to access different Dhis2 instances inside a single project):
|
48
|
-
|
49
|
-
```ruby
|
48
|
+
|
49
|
+
```ruby
|
50
50
|
client = Dhis2::Client.new(url: "https://play.dhis2.org/demo", user: "admin", password: "district")
|
51
51
|
client.data_elements.list # => Array[<DataElement>,..]
|
52
52
|
|
@@ -57,7 +57,7 @@ The functionalities are available as a module. First thing you need to do is to
|
|
57
57
|
|
58
58
|
Regarding SSL, there is an option to disregard SSL error messages (such as bad certificates). USE THIS AT YOUR OWN RISK - it may allow you to access a server that would return in error without it... but you cannot trust the response.
|
59
59
|
|
60
|
-
```ruby
|
60
|
+
```ruby
|
61
61
|
dangerous_client = Dhis2::Client.new(url: "https://play.dhis2.org/demo", user: "admin", password: "district", no_ssl_verification: true);
|
62
62
|
```
|
63
63
|
|
@@ -83,7 +83,7 @@ Following the DHIS2 API, all calls are paginated - you can access the page info
|
|
83
83
|
|
84
84
|
org_units = Dhis2.client.organisation_units.list(filter: "level:eq:2", fields: %w(id level displayName parent))
|
85
85
|
org_units.pager.page # current page
|
86
|
-
org_units.pager.page_count # number of pages
|
86
|
+
org_units.pager.page_count # number of pages
|
87
87
|
org_units.pager.total # number of records
|
88
88
|
|
89
89
|
### Retreive a single element
|
@@ -112,7 +112,7 @@ You can retreive data values this way:
|
|
112
112
|
organisation_unit = Dhis2.client.organisation_units.find_by(name: "Baoma")
|
113
113
|
period = "201512"
|
114
114
|
value_sets = Dhis2.client.data_value_sets.list(
|
115
|
-
data_sets: [ds.id],
|
115
|
+
data_sets: [ds.id],
|
116
116
|
organisation_unit: organisation_unit.id, periods: [period]
|
117
117
|
)
|
118
118
|
|
@@ -125,6 +125,8 @@ The API is currently limited to **read** actions on the following elements/class
|
|
125
125
|
* `DataElement`
|
126
126
|
* `DataSet`
|
127
127
|
* `CategoryCombo`
|
128
|
+
* `SystemInfos`
|
129
|
+
* `Attribute`
|
128
130
|
|
129
131
|
A very basic **write** use case exists for `DataElement` and `DataSet`:
|
130
132
|
|
@@ -144,6 +146,28 @@ DHIS2 API does not return the ids of the created elements, but you can retreive
|
|
144
146
|
status = Dhis2.client.data_elements.create(elements)
|
145
147
|
element = Dhis2.client.data_elements.find_by(name: "TesTesT2")
|
146
148
|
|
149
|
+
## Update
|
150
|
+
|
151
|
+
### Full update
|
152
|
+
|
153
|
+
You can update a given item by retreiving it using it's id, making any modification on it then calling "update":
|
154
|
+
|
155
|
+
org_unit = Dhis2.client.organisation_units.find(id)
|
156
|
+
org_unit.short_name = "New Short Name"
|
157
|
+
org_unit.update
|
158
|
+
|
159
|
+
This uses DHIS2 "full update" ('PUT') and not the "partial update" feature (see below), so it requires a fully formed object to work (get it either with `find` which takes all the fields or with the `fields: :all´ option).
|
160
|
+
|
161
|
+
### Partial update
|
162
|
+
|
163
|
+
You can update a single or more attributes via the "update_attributes" method:
|
164
|
+
|
165
|
+
org_unit = Dhis2.client.organisation_units.list(fields: :all, filter: "name:eq:#{org_unit_name}").first
|
166
|
+
new_attributes = { name: "New name" }
|
167
|
+
org_unit.update_attributes(new_attributes)
|
168
|
+
|
169
|
+
Note that partial updates will no work with custom attributes at this time (while the full update will)
|
170
|
+
|
147
171
|
## Development
|
148
172
|
|
149
173
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. Note that the tests are using the DHIS2 demo server, which is reset every day but can be updated by anyone - so if someone change the password of the default user, the tests are going to fail.
|
data/dhis2.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.12"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "minitest-reporters"
|
28
|
+
spec.add_development_dependency "faker", "~> 1.6", ">= 1.6.3"
|
27
29
|
end
|
data/lib/dhis2/api/base.rb
CHANGED
@@ -79,6 +79,7 @@ module Dhis2
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def initialize(client, raw_data)
|
82
|
+
raw_data["display_name"] ||= raw_data["name"] # for backward compatbility with v2.19
|
82
83
|
super(raw_data)
|
83
84
|
self.client = client
|
84
85
|
end
|
@@ -99,6 +100,10 @@ module Dhis2
|
|
99
100
|
def ==(other)
|
100
101
|
self.class == other.class && id == other.id
|
101
102
|
end
|
103
|
+
|
104
|
+
def update
|
105
|
+
client.put("#{self.class.resource_name}/#{id}", self.to_h)
|
106
|
+
end
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
@@ -3,21 +3,21 @@ module Dhis2
|
|
3
3
|
class DataElement < Base
|
4
4
|
class << self
|
5
5
|
def create(client, elements)
|
6
|
-
elements
|
7
|
-
|
6
|
+
elements = [elements].flatten
|
7
|
+
category_combo = client.category_combos.find_by(name: "default")
|
8
8
|
|
9
9
|
data_element = {
|
10
10
|
data_elements: elements.map do |element|
|
11
11
|
{
|
12
|
-
name:
|
13
|
-
short_name:
|
14
|
-
code:
|
15
|
-
domain_type:
|
16
|
-
value_type:
|
17
|
-
aggregation_type:
|
18
|
-
type:
|
12
|
+
name: element[:name],
|
13
|
+
short_name: element[:short_name],
|
14
|
+
code: element[:code] || element[:short_name],
|
15
|
+
domain_type: element[:domain_type] || "AGGREGATE",
|
16
|
+
value_type: element[:value_type] || "NUMBER",
|
17
|
+
aggregation_type: element[:aggregation_type] || "SUM",
|
18
|
+
type: element[:type] || "int", # for backward compatbility
|
19
19
|
aggregation_operator: element[:aggregation_type] || "SUM", # for backward compatbility
|
20
|
-
category_combo:
|
20
|
+
category_combo: { id: category_combo.id, name: category_combo.name }
|
21
21
|
}
|
22
22
|
end
|
23
23
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Dhis2
|
2
3
|
module Api
|
3
4
|
class DataElementGroup < Base
|
@@ -6,11 +7,19 @@ module Dhis2
|
|
6
7
|
groups = [groups].flatten
|
7
8
|
de_groups = {
|
8
9
|
data_element_groups: groups.map do |group|
|
9
|
-
{
|
10
|
+
mapped_group = {
|
10
11
|
name: group[:name],
|
11
12
|
short_name: group[:short_name],
|
12
13
|
code: group[:code] || group[:short_name]
|
13
14
|
}
|
15
|
+
|
16
|
+
if group[:data_elements]
|
17
|
+
data_elements = group[:data_elements].map do |element|
|
18
|
+
{ id: element[:id] }
|
19
|
+
end
|
20
|
+
mapped_group[:data_elements] = data_elements
|
21
|
+
end
|
22
|
+
mapped_group
|
14
23
|
end
|
15
24
|
}
|
16
25
|
response = client.post("metadata", de_groups)
|
data/lib/dhis2/api/data_set.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Dhis2
|
2
3
|
module Api
|
3
4
|
class DataSet < Base
|
4
5
|
class << self
|
5
6
|
def create(client, sets)
|
6
|
-
sets
|
7
|
+
sets = [sets].flatten
|
8
|
+
|
9
|
+
category_combo_id = client.category_combos.find_by(name: "default").id
|
10
|
+
|
7
11
|
data_set = {
|
8
12
|
data_sets: sets.map do |set|
|
9
13
|
{
|
@@ -12,7 +16,8 @@ module Dhis2
|
|
12
16
|
code: set[:code],
|
13
17
|
period_type: "Monthly",
|
14
18
|
data_elements: set[:data_element_ids] ? set[:data_element_ids].map { |id| { id: id } } : [],
|
15
|
-
organisation_units: set[:organisation_unit_ids] ? set[:organisation_unit_ids].map { |id| { id: id } } : []
|
19
|
+
organisation_units: set[:organisation_unit_ids] ? set[:organisation_unit_ids].map { |id| { id: id } } : [],
|
20
|
+
category_combo: { id: category_combo_id }
|
16
21
|
}
|
17
22
|
end
|
18
23
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Dhis2
|
2
3
|
module Api
|
3
4
|
class DataValueSet < Base
|
@@ -10,28 +11,58 @@ module Dhis2
|
|
10
11
|
class << self
|
11
12
|
def create(client, tuples)
|
12
13
|
body = { dataValues: tuples }
|
13
|
-
response = client.post(
|
14
|
+
response = client.post(resource_name, body)
|
14
15
|
Dhis2::Status.new(response)
|
15
16
|
end
|
16
17
|
|
17
18
|
def list(client, options)
|
18
|
-
|
19
|
-
|
19
|
+
new(client, client.get(build_list_url(client, options)))
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def build_list_url(_client, options)
|
23
|
+
params = [build_what_url(options), build_when_url(options), build_where_url(options)].join("&")
|
24
|
+
resource_name + "?" + params
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
def build_what_url(options)
|
28
|
+
data_set_ids = options[:data_sets]
|
29
|
+
if data_set_ids
|
30
|
+
data_sets_url = data_set_ids.map { |ds| "dataSet=#{ds}" }.join("&")
|
26
31
|
else
|
27
|
-
|
32
|
+
data_element_groups = options[:data_element_groups]
|
33
|
+
data_sets_url = data_element_groups.map { |deg| "dataElementGroup=#{deg}" }.join("&") if data_element_groups
|
28
34
|
end
|
35
|
+
end
|
29
36
|
|
30
|
-
|
31
|
-
periods
|
37
|
+
def build_when_url(options)
|
38
|
+
periods = options[:periods]
|
39
|
+
if periods
|
40
|
+
periods = periods.map { |period| "period=#{period}" }.join("&")
|
41
|
+
else
|
42
|
+
start_date = options[:start_date]
|
43
|
+
end_date = options[:end_date]
|
44
|
+
date_args = []
|
45
|
+
date_args.push "startDate=#{start_date}" if start_date
|
46
|
+
date_args.push "endDate=#{end_date}" if end_date
|
47
|
+
periods = date_args.join("&")
|
48
|
+
end
|
49
|
+
periods
|
50
|
+
end
|
32
51
|
|
33
|
-
|
34
|
-
|
52
|
+
def build_where_url(options)
|
53
|
+
children = options[:children] || true
|
54
|
+
organisation_unit_id = options[:organisation_unit]
|
55
|
+
organisation_unit_group = options[:organisation_unit_group]
|
56
|
+
if organisation_unit_id
|
57
|
+
if organisation_unit_id.class == Array
|
58
|
+
ou_url = organisation_unit_id.map { |ou_id| "orgUnit=#{ou_id}" }.join("&") + "&children=#{children}"
|
59
|
+
else
|
60
|
+
ou_url = "orgUnit=#{organisation_unit_id}&children=#{children}"
|
61
|
+
end
|
62
|
+
else
|
63
|
+
ou_url = "orgUnitGroup=#{organisation_unit_group}"
|
64
|
+
end
|
65
|
+
ou_url
|
35
66
|
end
|
36
67
|
end
|
37
68
|
end
|
@@ -6,6 +6,25 @@ module Dhis2
|
|
6
6
|
organisation_unit["id"]
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def create(client, orgunit_groups)
|
12
|
+
orgunit_groups = [orgunit_groups].flatten
|
13
|
+
ou_groups = {
|
14
|
+
organisation_unit_groups: orgunit_groups.map do |orgunit_group|
|
15
|
+
mapped_orgunit_group = {
|
16
|
+
name: orgunit_group[:name],
|
17
|
+
short_name: orgunit_group[:short_name],
|
18
|
+
code: orgunit_group[:code] || orgunit_group[:short_name]
|
19
|
+
}
|
20
|
+
mapped_orgunit_group[:id] = orgunit_group[:id] if orgunit_group[:id]
|
21
|
+
mapped_orgunit_group
|
22
|
+
end
|
23
|
+
}
|
24
|
+
response = client.post("metadata", ou_groups)
|
25
|
+
Dhis2::Status.new(response)
|
26
|
+
end
|
27
|
+
end
|
9
28
|
end
|
10
29
|
end
|
11
30
|
end
|
data/lib/dhis2/pager.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Dhis2
|
3
|
+
class Pager
|
4
|
+
attr_reader :page, :page_count, :total, :next_page
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(hash)
|
7
|
+
@page = hash["page"]
|
8
|
+
@page_count = hash["page_count"]
|
9
|
+
@total = hash["total"]
|
10
|
+
@next_page = hash["next_page"]
|
11
|
+
end
|
9
12
|
end
|
10
13
|
end
|
data/lib/dhis2/version.rb
CHANGED
data/lib/dhis2.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "rest-client"
|
2
3
|
require "json"
|
3
4
|
require "ostruct"
|
@@ -26,6 +27,8 @@ require_relative "dhis2/api/organisation_unit_level"
|
|
26
27
|
require_relative "dhis2/api/indicator"
|
27
28
|
require_relative "dhis2/api/analytic"
|
28
29
|
require_relative "dhis2/api/organisation_unit_group"
|
30
|
+
require_relative "dhis2/api/system_info"
|
31
|
+
require_relative "dhis2/api/attribute"
|
29
32
|
|
30
33
|
module Dhis2
|
31
34
|
class << self
|
@@ -34,18 +37,16 @@ module Dhis2
|
|
34
37
|
if config.user.nil? && config.password.nil?
|
35
38
|
@client ||= Dhis2::Client.new(config.url)
|
36
39
|
else
|
37
|
-
@client ||= Dhis2::Client.new(
|
38
|
-
|
39
|
-
|
40
|
-
password: config.password
|
41
|
-
})
|
40
|
+
@client ||= Dhis2::Client.new(url: config.url,
|
41
|
+
user: config.user,
|
42
|
+
password: config.password)
|
42
43
|
end
|
43
44
|
else
|
44
45
|
@client
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
def configure
|
49
|
+
def configure
|
49
50
|
yield config
|
50
51
|
end
|
51
52
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhis2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Van Aken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -66,6 +66,40 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faker
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.6.3
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '1.6'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.6.3
|
69
103
|
description: Allows to retreive items from a DHIS2 server in a more "Ruby way".
|
70
104
|
email:
|
71
105
|
- mvanaken@bluesquare.org
|
@@ -86,6 +120,7 @@ files:
|
|
86
120
|
- dhis2.gemspec
|
87
121
|
- lib/dhis2.rb
|
88
122
|
- lib/dhis2/api/analytic.rb
|
123
|
+
- lib/dhis2/api/attribute.rb
|
89
124
|
- lib/dhis2/api/base.rb
|
90
125
|
- lib/dhis2/api/category_combo.rb
|
91
126
|
- lib/dhis2/api/data_element.rb
|
@@ -97,6 +132,7 @@ files:
|
|
97
132
|
- lib/dhis2/api/organisation_unit.rb
|
98
133
|
- lib/dhis2/api/organisation_unit_group.rb
|
99
134
|
- lib/dhis2/api/organisation_unit_level.rb
|
135
|
+
- lib/dhis2/api/system_info.rb
|
100
136
|
- lib/dhis2/client.rb
|
101
137
|
- lib/dhis2/collection_wrapper.rb
|
102
138
|
- lib/dhis2/configuration.rb
|