orthanc 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd7892469761f2610ebec1e93d457212a0231f4a
4
- data.tar.gz: 6b5a8cbd7aac358337ca577e914997479473d97a
3
+ metadata.gz: 509d31ee74414e383409a5189892149d32457ce2
4
+ data.tar.gz: 9867650b3e71e828cc86ae3c1096b1220fb0d792
5
5
  SHA512:
6
- metadata.gz: 1c6b7a5e8a156cf63bc64e80847d5f319dd3c9a197aec2622d49223feb451d2765d12d2a6e4410959c8815387bcaba61004ae77144a914701054a8ff0c257a50
7
- data.tar.gz: 3541b04589e433c39e98cc8c56b1490efa2e843d98bc92e5b329d8cd6516eeb69b59afb3ef8d2ba88ce6694539894d60c9fb827ffd47195799a111a776d18208
6
+ metadata.gz: 2fc432f1593ad9c8a64c8042de72fc93360b36873f909fee6841977bdb533cb65ecd4db6b375f37a782a4e4a7a9a6cf279d4d5422f3355c4124b93955d653e0f
7
+ data.tar.gz: eda048fbf6e437af42013473290af66fd1234efc4d1f344372ad83a460f1f3e15d7d08294135e8230de03d43214237e6a731d3577a1cd44cf6d93ea78daacc96
data/README.md CHANGED
@@ -1,10 +1,17 @@
1
1
  # Orthanc-ruby
2
2
 
3
- ##### A Ruby implementation of the [Orthanc](http://orthanc-server.com) DICOM server v0.8.6 REST API
3
+ #### A Ruby implementation of the [Orthanc](http://orthanc-server.com) DICOM server v0.8.6 REST API
4
4
 
5
- ##### Extremely Alpha!! Not ready for production. Anything may change, including resource nesting and naming schemes.
5
+ ---
6
+
7
+ **Alpha!! Not ready for production. Anything may change, including resource nesting and naming schemes.**
8
+
9
+ ---
10
+
11
+ ###Attention: The gem now implements the orthanc resources as multilevel methods, to make it more Ruby-like
12
+
13
+ _(This is my first API client gem, experienced help or advice would be most appreciated)_ :)
6
14
 
7
- (This is my first API client gem, experienced help or advice would be most appreciated) :)
8
15
 
9
16
  ## Installation
10
17
 
@@ -28,8 +35,12 @@ Or install it yourself as:
28
35
  The gem tries to follow the Orthanc API naming scheme as closely as possible, converting methods and response items to snake case to make the experience more ruby-like.
29
36
 
30
37
  api=Orthanc::Client.new("localhost", "8042")
31
- api.all_patients
32
- api.all_patients.first
38
+ api.patients # All patients as instances for method chaining
39
+ api.patients_list # Patient array, from Orthanc response
40
+ pat = api.patients.first # First patient (instance)
41
+
42
+ pat.shared_tags(simplify:true) # Patient's shared tags (simplified)
43
+
33
44
  api.system.database_version => 5
34
45
  api.statistics.count_studies => 14
35
46
 
@@ -39,7 +50,13 @@ You can see what Orthanc API resources have been mapped in the gem, and their st
39
50
 
40
51
  Basic documentation can be found in [here](http://www.rubydoc.info/github/simonmd/orthanc-ruby/master/Orthanc/Client)
41
52
 
53
+ ## Backlog
42
54
 
55
+ - Methods that return a file should be handled by ruby
56
+ - Test attachments (not sure how they are implemented in Orthanc)
57
+ - Handle network errors, return false if 500 Server error? (eg. echo)
58
+ - Test peers
59
+ - Write automated tests
43
60
 
44
61
  ## Contributing
45
62
 
@@ -0,0 +1,57 @@
1
+ module Orthanc
2
+ class Attachment
3
+ include Response
4
+ attr_accessor :base_uri
5
+
6
+ def initialize(resource, id = nil)
7
+ self.base_uri = resource["/attachments/#{id}"]
8
+ end
9
+
10
+
11
+ # DELETE /{resourceType}/{id}/attachments/{name}
12
+ def delete_attachment
13
+ handle_response(base_uri["attachments/#{name}"].delete)
14
+ end
15
+
16
+ # PUT /{resourceType}/{id}/attachments/{name}
17
+ def modify(payload = {})
18
+ handle_response(base_uri["attachments/#{name}"].put(payload))
19
+ end
20
+
21
+ # GET /{resourceType}/{id}/attachments/{name}/compressed-data
22
+ def compressed_data
23
+ handle_response(base_uri["compressed-data"].get)
24
+ end
25
+
26
+ # GET /{resourceType}/{id}/attachments/{name}/compressed-md5
27
+ def compressed_md5
28
+ handle_response(base_uri["compressed-md5"].get)
29
+ end
30
+
31
+ # GET /{resourceType}/{id}/attachments/{name}/compressed-size
32
+ def compressed_size
33
+ handle_response(base_uri["compressed-size"].get)
34
+ end
35
+
36
+ # GET /{resourceType}/{id}/attachments/{name}/data
37
+ def data
38
+ handle_response(base_uri["data"].get)
39
+ end
40
+
41
+ # GET /{resourceType}/{id}/attachments/{name}/md5
42
+ def md5
43
+ handle_response(base_uri["md5"].get)
44
+ end
45
+
46
+ # GET /{resourceType}/{id}/attachments/{name}/size
47
+ def size
48
+ handle_response(base_uri["size"].get)
49
+ end
50
+
51
+ # POST /{resourceType}/{id}/attachments/{name}/verify-md5
52
+ def verify_md5
53
+ handle_response(base_uri["verify-md5"].get)
54
+ end
55
+
56
+ end
57
+ end
@@ -1,3 +1,5 @@
1
+ require 'orthanc/response'
2
+
1
3
  require 'orthanc/tools'
2
4
  require 'orthanc/plugins'
3
5
  require 'orthanc/modalities'
@@ -6,68 +8,191 @@ require 'orthanc/patients'
6
8
  require 'orthanc/studies'
7
9
  require 'orthanc/series'
8
10
  require 'orthanc/instances'
11
+ require 'orthanc/attachments'
12
+ require 'orthanc/metadata'
9
13
 
10
14
  module Orthanc
11
15
  class Client
12
16
 
17
+ include Response
13
18
  attr_accessor :base_uri
14
19
 
15
- def initialize(host,port = 8042)
20
+ def initialize(host = "localhost", port = 8042)
16
21
  self.base_uri = RestClient::Resource.new("http://#{host}:#{port}")
17
22
  end
18
23
 
19
24
  # ------------- General -------------
25
+
26
+ # GET /system
20
27
  def system
21
28
  handle_response(base_uri["system"].get)
22
29
  end
23
30
 
31
+ # GET /statistics
24
32
  def statistics
25
33
  handle_response(base_uri["statistics"].get)
26
34
  end
27
35
 
36
+ # GET /changes
28
37
  def changes(params = {}) # "last", "limit" and "since" arguments
29
38
  handle_response(base_uri["changes"].get({params: params}))
30
39
  end
31
40
 
41
+ # DELETE /changes
32
42
  def delete_changes(params = {}) # "last", "limit" and "since" arguments
33
43
  handle_response(base_uri["changes"].delete({params: params}))
34
44
  end
35
45
 
46
+ # GET /exports
36
47
  def exports(params = {}) # "last", "limit" and "since" arguments
37
48
  handle_response(base_uri["exports"].get({params: params}))
38
49
  end
39
50
 
51
+ # DELETE /exports
40
52
  def delete_exports(params = {}) # "last", "limit" and "since" arguments
41
53
  handle_response(base_uri["exports"].delete({params: params}))
42
54
  end
43
55
 
44
56
 
45
- private
57
+ # ------------- Plugins -------------
58
+
59
+ # GET /plugins
60
+ def plugins_list # Orthanc endpoint response
61
+ handle_response(base_uri["plugins"].get)
62
+ end
63
+
64
+ # GET /plugins
65
+ def plugins(id = nil) # As class instances, for method chaining
66
+ if id
67
+ return Plugin.new(id)
68
+ else
69
+ a = []
70
+ handle_response(base_uri["plugins"].get).each do |id|
71
+ a << Plugin.new(id)
72
+ end
73
+ return a
74
+ end
75
+ end
76
+
77
+
78
+ # ------------- Tools -------------
79
+
80
+ # GET /tools
81
+ def tools
82
+ Tool.new
83
+ end
84
+
85
+
86
+ # ------------- Modalities -------------
46
87
 
47
- def bool_to_num(bool)
48
- return 0 if bool == false
49
- return 1 if bool == true
88
+ def modalities_list # Orthanc endpoint response
89
+ handle_response(base_uri["modalities"].get)
50
90
  end
51
91
 
52
- def num_to_bool(num)
53
- return false if num == "0"
54
- return true if num == "1"
92
+ def modalities(dicom = nil) # As class instances, for method chaining
93
+ if dicom
94
+ return Modality.new(dicom)
95
+ else
96
+ a = []
97
+ handle_response(base_uri["modalities"].get).each do |dicom|
98
+ a << Modality.new(dicom)
99
+ end
100
+ return a
101
+ end
102
+ end
103
+
104
+
105
+ # ------------- Modalities -------------
106
+
107
+ def peers_list # Orthanc endpoint response
108
+ handle_response(base_uri["peers"].get)
55
109
  end
56
110
 
57
- def handle_response(response)
58
- begin
59
- # Try to parse response
60
- parsed_response = JSON.parse(response)
111
+ def peers(peer = nil) # As class instances, for method chaining
112
+ if peer
113
+ return Peer.new(peer)
114
+ else
115
+ a = []
116
+ handle_response(base_uri["peers"].get).each do |peer|
117
+ a << Peer.new(peer)
118
+ end
119
+ return a
120
+ end
121
+ end
122
+
123
+
124
+ # ------------- Patients -------------
125
+
126
+ def patients_list # Orthanc endpoint response
127
+ handle_response(base_uri["patients"].get)
128
+ end
129
+
130
+ def patients(id = nil) # As class instances, for method chaining
131
+ if id
132
+ return Patient.new(id)
133
+ else
134
+ a = []
135
+ handle_response(base_uri["patients"].get).each do |id|
136
+ a << Patient.new(id)
137
+ end
138
+ return a
139
+ end
140
+ end
141
+
142
+
143
+ # ------------- Studies -------------
144
+
145
+ def studies_list # Orthanc endpoint response
146
+ handle_response(base_uri["studies"].get)
147
+ end
148
+
149
+ def studies(id = nil) # As class instances, for method chaining
150
+ if id
151
+ return Study.new(id)
152
+ else
153
+ a = []
154
+ handle_response(base_uri["studies"].get).each do |id|
155
+ a << Study.new(id)
156
+ end
157
+ return a
158
+ end
159
+ end
160
+
161
+
162
+ # ------------- Series -------------
163
+
164
+ def series_list # Orthanc endpoint response
165
+ handle_response(base_uri["series"].get)
166
+ end
167
+
168
+ def series(id = nil) # As class instances, for method chaining
169
+ if id
170
+ return Series.new(id)
171
+ else
172
+ a = []
173
+ handle_response(base_uri["series"].get).each do |id|
174
+ a << Series.new(id)
175
+ end
176
+ return a
177
+ end
178
+ end
179
+
180
+
181
+ # ------------- Instances -------------
182
+
183
+ def instances_list # Orthanc endpoint response
184
+ handle_response(base_uri["instances"].get)
185
+ end
61
186
 
62
- if parsed_response.class == Array
63
- return parsed_response
64
- elsif parsed_response.class == Hash
65
- return RecursiveOpenStruct.new(parsed_response.to_snake_keys, recurse_over_arrays: true )
66
- else
67
- return response
187
+ def instances(id = nil) # As class instances, for method chaining
188
+ if id
189
+ return Instance.new(id)
190
+ else
191
+ a = []
192
+ handle_response(base_uri["instances"].get).each do |id|
193
+ a << Instance.new(id)
68
194
  end
69
- rescue JSON::ParserError => e # If JSON parse fails, return original response
70
- return response
195
+ return a
71
196
  end
72
197
  end
73
198
 
@@ -1,222 +1,185 @@
1
1
  module Orthanc
2
- class Client
3
- # ------------- Instances -------------
2
+ class Instance
3
+ include Response
4
+ attr_accessor :base_uri
4
5
 
5
- # GET /instances
6
- def all_instances
7
- handle_response(base_uri["instances"].get)
6
+ def initialize(id = nil)
7
+ client = Client.new
8
+ self.base_uri = client.base_uri["/instances/#{id}"]
8
9
  end
9
10
 
10
- # POST /instances
11
- def instances(dicom_file) # POST = Add the new DICOM file given in the POST body
12
- handle_response(base_uri["instances"].post(dicom_file))
13
- end
14
-
15
- # GET /instances/{id}
16
- def instance(id)
17
- handle_response(base_uri["instances/#{id}"].get)
11
+ # GET /instances, # GET /instances/{id}
12
+ def fetch # Fetch API response
13
+ handle_response(base_uri.get)
18
14
  end
19
15
 
20
16
  # DELETE /instances/{id}
21
- def delete_instance(id)
22
- handle_response(base_uri["instances/#{id}"].delete)
17
+ def delete
18
+ handle_response(base_uri.delete)
23
19
  end
24
20
 
25
21
  # POST /instances/{id}/anonymize
26
- def anonymize_instance(id, payload = {}) # https://code.google.com/p/orthanc/wiki/Anonymization
27
- base_uri["instances/#{id}/anonymize"].post(payload.to_s)
22
+ def anonymize(payload = {}) # https://code.google.com/p/orthanc/wiki/Anonymization
23
+ base_uri["anonymize"].post(payload.to_s)
28
24
  end
29
25
 
30
26
  # GET /instances/{id}/content/
31
- def instance_content(id) # List the first-level DICOM tags
32
- handle_response(base_uri["instances/#{id}/frames"].get)
27
+ def content # List the first-level DICOM tags
28
+ handle_response(base_uri["frames"].get)
33
29
  end
34
30
 
35
31
  # GET /instances/{id}/content/{group}-{element}
36
- def instance_content_tag(id, group, element) # Raw access to the value of DICOM tags (comprising the padding character)
37
- handle_response(base_uri["instances/#{id}/content/#{group}-#{element}"].get)
32
+ def content_tag(group, element) # Raw access to the value of DICOM tags (comprising the padding character)
33
+ handle_response(base_uri["content/#{group}-#{element}"].get)
38
34
  end
39
35
 
40
36
  # GET /instances/{id}/content/{group}-{element}/{index}/...
41
- def instance_content_sequence(id, group, element, index) # Raw access to the content of DICOM sequences
42
- handle_response(base_uri["instances/#{id}/content/#{group}-#{element}/#{index}"].get)
37
+ def content_sequence(group, element, index) # Raw access to the content of DICOM sequences
38
+ handle_response(base_uri["content/#{group}-#{element}/#{index}"].get)
43
39
  end
44
40
 
45
41
  # POST /instances/{id}/export
46
- def instance_export(id, payload = {}) # Write the DICOM file in the filesystem where Orthanc is running
47
- base_uri["instances/#{id}/export"].post(payload)
42
+ def export(payload = {}) # Write the DICOM file in the filesystem where Orthanc is running
43
+ base_uri["export"].post(payload)
48
44
  end
49
45
 
50
46
  # GET /instances/{id}/file
51
- def instance_file(id)
52
- base_uri["instances/#{id}/file"].get
47
+ def file
48
+ base_uri["file"].get
53
49
  end
54
50
 
55
51
  # GET /instances/{id}/frames
56
- def instance_frames(id) # Instance frames array
57
- handle_response(base_uri["instances/#{id}/frames"].get)
52
+ def frames # Instance frames array
53
+ handle_response(base_uri["frames"].get)
58
54
  end
59
55
 
60
56
  # GET /instances/{id}/frames/{frameNumber}/image-int16
61
- def instance_frame_image_int16(id, frame_number) # Truncated image to the [-32768;32767] range
62
- base_uri["instances/#{id}/frames/#{frame_number}/image-int16"].get
57
+ def frame_image_int16(frame_number) # Truncated image to the [-32768;32767] range
58
+ base_uri["frames/#{frame_number}/image-int16"].get
63
59
  end
64
60
 
65
61
  # GET /instances/{id}/frames/{frameNumber}/image-uint16
66
- def instance_frame_image_uint16(id, frame_number) # Truncated image to the [0;65535] range
67
- base_uri["instances/#{id}/frames/#{frame_number}/image-uint16"].get
62
+ def frame_image_uint16(frame_number) # Truncated image to the [0;65535] range
63
+ base_uri["frames/#{frame_number}/image-uint16"].get
68
64
  end
69
65
 
70
66
  # GET /instances/{id}/frames/{frameNumber}/image-uint8
71
- def instance_frame_image_uint8(id, frame_number) # Truncated image to the [0;255] range
72
- base_uri["instances/#{id}/frames/#{frame_number}/image-uint8"].get
67
+ def frame_image_uint8(frame_number) # Truncated image to the [0;255] range
68
+ base_uri["frames/#{frame_number}/image-uint8"].get
73
69
  end
74
70
 
75
71
  # GET /instances/{id}/frames/{frameNumber}/matlab
76
- def instance_frame_matlab(id, frame_number) # a = eval(urlread('http://localhost:8042/instances/.../matlab'))
77
- base_uri["instances/#{id}/frames/#{frame_number}/matlab"].get
72
+ def frame_matlab(frame_number) # a = eval(urlread('http://localhost:8042/instances/.../matlab'))
73
+ base_uri["frames/#{frame_number}/matlab"].get
78
74
  end
79
75
 
80
76
  # GET /instances/{id}/frames/{frameNumber}/preview
81
- def instance_preview(id, frame_number) # Rescaled image (so that all the range [0;255] is used)
82
- base_uri["instances/#{id}/frames/#{frame_number}/preview"].get
77
+ def preview(frame_number) # Rescaled image (so that all the range [0;255] is used)
78
+ base_uri["frames/#{frame_number}/preview"].get
83
79
  end
84
80
 
85
81
  # GET /instances/{id}/image-int16
86
- def instance_image_int16(id) # Truncated image to the [-32768;32767] range
87
- base_uri["instances/#{id}/image-int16"].get
82
+ def image_int16 # Truncated image to the [-32768;32767] range
83
+ base_uri["image-int16"].get
88
84
  end
89
85
 
90
86
  # GET /instances/{id}/image-uint16
91
- def instance_image_uint16(id) # Truncated image to the [0;65535] range
92
- base_uri["instances/#{id}/image-uint16"].get
87
+ def image_uint16 # Truncated image to the [0;65535] range
88
+ base_uri["image-uint16"].get
93
89
  end
94
90
 
95
91
  # GET /instances/{id}/image-uint8
96
- def instance_image_uint8(id) # Truncated image to the [0;255] range
97
- base_uri["instances/#{id}/image-uint8"].get
92
+ def image_uint8 # Truncated image to the [0;255] range
93
+ base_uri["image-uint8"].get
98
94
  end
99
95
 
100
96
  # GET /instances/{id}/matlab
101
- def instance_matlab(id) # a = eval(urlread('http://localhost:8042/instances/.../matlab'))
102
- base_uri["instances/#{id}/matlab"].get
97
+ def matlab # a = eval(urlread('http://localhost:8042/instances/.../matlab'))
98
+ base_uri["matlab"].get
103
99
  end
104
100
 
105
101
  # POST /instances/{id}/modify
106
- def modify_instance(id, payload = {}) # https://code.google.com/p/orthanc/wiki/Anonymization
107
- base_uri["instances/#{id}/modify"].post(payload.to_s)
102
+ def modify(payload = {}) # https://code.google.com/p/orthanc/wiki/Anonymization
103
+ base_uri["modify"].post(payload.to_s)
108
104
  end
109
105
 
110
106
  # GET /instances/{id}/module
111
- def instance_module(id)
112
- handle_response(base_uri["instances/#{id}/module"].get)
107
+ def module
108
+ handle_response(base_uri["module"].get)
113
109
  end
114
110
 
115
111
  # GET /instances/{id}/patient
116
- def instance_patient(id)
117
- handle_response(base_uri["instances/#{id}/patient"].get)
112
+ def patient
113
+ handle_response(base_uri["patient"].get)
118
114
  end
119
115
 
120
116
  # GET /instances/{id}/preview
121
- def instance_preview(id) # Rescaled image (so that all the range [0;255] is used)
122
- handle_response(base_uri["instances/#{id}/preview"].get)
117
+ def preview # Rescaled image (so that all the range [0;255] is used)
118
+ handle_response(base_uri["preview"].get)
123
119
  end
124
120
 
125
121
  # GET /instances/{id}/series
126
- def instance_series(id)
127
- handle_response(base_uri["instances/#{id}/series"].get)
122
+ def series
123
+ handle_response(base_uri["series"].get)
128
124
  end
129
125
 
130
126
  # GET /instances/{id}/simplified-tags
131
- def instance_simplified_tags(id) # "?simplify" argument to simplify output
132
- handle_response(base_uri["instances/#{id}/simplified-tags"].get)
127
+ def simplified_tags(params = {}) # "?simplify" argument to simplify output
128
+ handle_response(base_uri["simplified-tags"].get({params: params}))
133
129
  end
134
130
 
135
131
  # GET /instances/{id}/statistics
136
- def instance_statistics(id)
137
- handle_response(base_uri["instances/#{id}/statistics"].get)
132
+ def statistics
133
+ handle_response(base_uri["statistics"].get)
138
134
  end
139
135
 
140
136
  # GET /instances/{id}/study
141
- def instance_study(id)
142
- handle_response(base_uri["instances/#{id}/study"].get)
137
+ def study
138
+ handle_response(base_uri["study"].get)
143
139
  end
144
140
 
145
141
  # GET /instances/{id}/tags
146
- def instance_tags(id) # TODO: "?simplify" argument to simplify output (same as "simplified-tags")
147
- handle_response(base_uri["instances/#{id}/tags"].get)
142
+ def tags(params = {}) # TODO: "?simplify" argument to simplify output (same as "simplified-tags")
143
+ handle_response(base_uri["tags"].get({params: params}))
148
144
  end
149
145
 
150
- # TODO: Polymorphic resourceType resources. Repetitive. must refactor
146
+ # ---------- Polymorphic resources ----------
147
+ # Attachments
151
148
 
152
149
  # GET /{resourceType}/{id}/attachments
153
- def instance_attachments(id)
154
- handle_response(base_uri["instances/#{id}/attachments"].get)
155
- end
156
-
157
- # DELETE /{resourceType}/{id}/attachments/{name}
158
- def delete_instance_attachment(id, name)
159
- handle_response(base_uri["instances/#{id}/attachments/#{name}"].delete)
160
- end
161
-
162
- # PUT /{resourceType}/{id}/attachments/{name}
163
- def instance_attachment(id, name, payload = {})
164
- handle_response(base_uri["instances/#{id}/attachments/#{name}"].put(payload))
150
+ def attachments_list # Orthanc endpoint response
151
+ handle_response(base_uri["attachments"].get)
165
152
  end
166
153
 
167
- # GET /{resourceType}/{id}/attachments/{name}/compressed-data
168
- def instance_attachment_compressed_data(id, name)
169
- handle_response(base_uri["instances/#{id}/attachments/#{name}/compressed-data"].get)
154
+ def attachments(id = nil)
155
+ if id
156
+ return Attachment.new(base_uri, id)
157
+ else
158
+ a = []
159
+ handle_response(base_uri["attachments"].get).each do |id|
160
+ a << Attachment.new(base_uri, id)
161
+ end
162
+ return a
163
+ end
170
164
  end
171
165
 
172
- # GET /{resourceType}/{id}/attachments/{name}/compressed-md5
173
- def instance_attachment_compressed_md5(id, name)
174
- handle_response(base_uri["instances/#{id}/attachments/#{name}/compressed-md5"].get)
175
- end
176
-
177
- # GET /{resourceType}/{id}/attachments/{name}/compressed-size
178
- def instance_attachment_compressed_size(id, name)
179
- handle_response(base_uri["instances/#{id}/attachments/#{name}/compressed-size"].get)
180
- end
181
-
182
- # GET /{resourceType}/{id}/attachments/{name}/data
183
- def instance_attachment_data(id, name)
184
- handle_response(base_uri["instances/#{id}/attachments/#{name}/data"].get)
185
- end
186
-
187
- # GET /{resourceType}/{id}/attachments/{name}/md5
188
- def instance_attachment_md5(id, name)
189
- handle_response(base_uri["instances/#{id}/attachments/#{name}/md5"].get)
190
- end
191
-
192
- # GET /{resourceType}/{id}/attachments/{name}/size
193
- def instance_attachment_size(id, name)
194
- handle_response(base_uri["instances/#{id}/attachments/#{name}/size"].get)
195
- end
196
-
197
- # POST /{resourceType}/{id}/attachments/{name}/verify-md5
198
- def instance_attachment_verify_md5(id, name)
199
- handle_response(base_uri["instances/#{id}/attachments/#{name}/verify-md5"].get)
200
- end
166
+ # Metadata
201
167
 
202
168
  # GET /{resourceType}/{id}/metadata
203
- def instance_all_metadata(id)
204
- handle_response(base_uri["instances/#{id}/metadata"].get)
205
- end
206
-
207
- # GET /{resourceType}/{id}/metadata/{name}
208
- def instance_metadata(id, name)
209
- handle_response(base_uri["instances/#{id}/metadata/#{name}"].get)
210
- end
211
-
212
- # DELETE /{resourceType}/{id}/metadata/{name}
213
- def instance_delete_metadata(id, name)
214
- handle_response(base_uri["instances/#{id}/metadata/#{name}"].delete)
215
- end
216
-
217
- # PUT /{resourceType}/{id}/metadata/{name}
218
- def instance_update_metadata(id, name, payload = {})
219
- handle_response(base_uri["instances/#{id}/metadata/#{name}"].put(payload))
169
+ def metadata_list # Orthanc endpoint response
170
+ handle_response(base_uri["metadata"].get)
171
+ end
172
+
173
+ def metadata(name = nil) # As class instances, for method chaining
174
+ if name
175
+ return Metadata.new(base_uri, name)
176
+ else
177
+ a = []
178
+ handle_response(base_uri["metadata"].get).each do |name|
179
+ a << Metadata.new(base_uri, name)
180
+ end
181
+ return a
182
+ end
220
183
  end
221
184
 
222
185
  end