lifen_fhir 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/lib/lifen_fhir/client.rb +15 -0
- data/lib/lifen_fhir/configuration.rb +13 -1
- data/lib/lifen_fhir/integrations/rails.rb +11 -0
- data/lib/lifen_fhir/integrations/railties.rb +1 -0
- data/lib/lifen_fhir/logger.rb +18 -0
- data/lib/lifen_fhir/version.rb +1 -1
- data/lib/lifen_fhir.rb +26 -0
- data/spec/cassettes/logger/invalid.yml +58 -0
- data/spec/cassettes/logger/valid.yml +58 -0
- data/spec/logger_spec.rb +53 -0
- data/spec/spec_helper.rb +1 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f268ed9c624f69baa94cf0c7b9ad04cf5778ffc
|
4
|
+
data.tar.gz: cfdeb52172b4385d3fce6a0a1f497931156669d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '003841d9ab0e8df08ae247d1c5d7c9b05c42e095af4c6c298778e1de768527f0f697679f95249a516e39240093cfb79d0aa3e1e8711d0ea59c012bce2b6185d3'
|
7
|
+
data.tar.gz: f05094f969f7c04dd8b8b5ba7774c89c21c6e84870b44a291bcac42cf5a9e9c91c394389d733c662d5aa04306e381e29060fcbf0a5e663c610cd91f48299e007
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,12 +31,14 @@ LifenFhir.configure do |config|
|
|
31
31
|
|
32
32
|
# optionnal
|
33
33
|
config.proxy_url = "http://my.proxy.fr/"
|
34
|
+
config.logger = Logger.new
|
34
35
|
end
|
35
36
|
```
|
36
37
|
|
37
38
|
Optionnal configuration:
|
38
39
|
|
39
|
-
- `proxy_url`:
|
40
|
+
- `proxy_url`: route all your requests via a proxy
|
41
|
+
- `logger`: log all requests to a custom logger (on Rails, `Rails.logger` is selected automatically)
|
40
42
|
|
41
43
|
### Internal
|
42
44
|
|
data/lib/lifen_fhir/client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module LifenFhir
|
2
2
|
class Client
|
3
3
|
|
4
|
+
LOGGED_INFO_STATUS = [200, 201]
|
5
|
+
|
4
6
|
def request(mode, url, params = {})
|
5
7
|
before_request
|
6
8
|
|
@@ -17,6 +19,7 @@ module LifenFhir
|
|
17
19
|
req.body = JSON.generate(params)
|
18
20
|
end
|
19
21
|
|
22
|
+
handle_logger(response)
|
20
23
|
handle_errors(response, params)
|
21
24
|
|
22
25
|
handle_response(response)
|
@@ -47,6 +50,14 @@ module LifenFhir
|
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
53
|
+
def handle_logger(response)
|
54
|
+
if LOGGED_INFO_STATUS.include? response.status
|
55
|
+
logger.info "*** [LIFEN] Success on #{response.env.method.upcase} '#{response.env.url}'"
|
56
|
+
else
|
57
|
+
logger.fatal "*** [LIFEN] #{response.status} Error on #{response.env.method.upcase} '#{response.env.url}'"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
50
61
|
def handle_response(response)
|
51
62
|
if response.headers['Content-Type'].match "json"
|
52
63
|
JSON.parse response.body
|
@@ -77,6 +88,10 @@ module LifenFhir
|
|
77
88
|
LifenFhir.configuration.proxy_url
|
78
89
|
end
|
79
90
|
|
91
|
+
def logger
|
92
|
+
LifenFhir.configuration.logger
|
93
|
+
end
|
94
|
+
|
80
95
|
def before_request
|
81
96
|
end
|
82
97
|
|
@@ -1,7 +1,19 @@
|
|
1
1
|
module LifenFhir
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
attr_accessor :site
|
4
|
+
attr_accessor :site
|
5
|
+
|
6
|
+
attr_accessor :application_access_token
|
7
|
+
|
8
|
+
attr_accessor :proxy_url
|
9
|
+
|
10
|
+
# Logger used by Lifen FHIR. In Rails, this is the Rails logger, otherwise
|
11
|
+
# Lifen FHIR provides its own LifenFhir::Logger.
|
12
|
+
attr_accessor :logger
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.logger = ::LifenFhir::Logger.new(STDOUT)
|
16
|
+
end
|
5
17
|
|
6
18
|
def site=(url)
|
7
19
|
if !/(.*)\/$/.match(url)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'lifen_fhir/integrations/rails'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module LifenFhir
|
4
|
+
class Logger < ::Logger
|
5
|
+
LOG_PREFIX = "*** [LIFEN] ".freeze
|
6
|
+
PROGNAME = "lifen_fhir".freeze
|
7
|
+
|
8
|
+
def initialize(*)
|
9
|
+
super
|
10
|
+
@level = ::Logger::INFO
|
11
|
+
original_formatter = ::Logger::Formatter.new
|
12
|
+
@default_formatter = proc do |severity, datetime, _progname, msg|
|
13
|
+
msg = "#{LOG_PREFIX}#{msg}"
|
14
|
+
original_formatter.call(severity, datetime, PROGNAME, msg)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/lifen_fhir/version.rb
CHANGED
data/lib/lifen_fhir.rb
CHANGED
@@ -19,6 +19,7 @@ module LifenFhir
|
|
19
19
|
|
20
20
|
require "lifen_fhir/version"
|
21
21
|
|
22
|
+
require 'lifen_fhir/logger'
|
22
23
|
require 'lifen_fhir/error'
|
23
24
|
require 'lifen_fhir/client'
|
24
25
|
require 'lifen_fhir/user_authenticated_client'
|
@@ -41,4 +42,29 @@ module LifenFhir
|
|
41
42
|
|
42
43
|
Virtus.finalize
|
43
44
|
|
45
|
+
AVAILABLE_INTEGRATIONS = %w(railties).freeze
|
46
|
+
|
47
|
+
class << self
|
48
|
+
extend Forwardable
|
49
|
+
|
50
|
+
def_delegators :logger
|
51
|
+
|
52
|
+
def inject
|
53
|
+
integrations_to_load = LifenFhir::AVAILABLE_INTEGRATIONS
|
54
|
+
|
55
|
+
integrations_to_load &= Gem.loaded_specs.keys
|
56
|
+
integrations_to_load.each do |integration|
|
57
|
+
load_integration(integration)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_integration(integration)
|
62
|
+
require "lifen_fhir/integrations/#{integration}"
|
63
|
+
rescue Exception => error
|
64
|
+
logger.warn "Unable to load lifen_fhir/integrations/#{integration}: #{error}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
44
68
|
end
|
69
|
+
|
70
|
+
LifenFhir.inject
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://develop.lifen.fr/invalid
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.11.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer valid_application_access_token
|
14
|
+
Accept:
|
15
|
+
- application/pdf
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 404
|
21
|
+
message: Not Found
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.6.2
|
25
|
+
Date:
|
26
|
+
- Wed, 05 Apr 2017 12:08:41 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/xml+fhir;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
X-B3-Sampled:
|
34
|
+
- '1'
|
35
|
+
X-B3-Spanid:
|
36
|
+
- fb30b5b1b27d94fe
|
37
|
+
X-B3-Traceid:
|
38
|
+
- fb30b5b1b27d94fe
|
39
|
+
X-Content-Type-Options:
|
40
|
+
- nosniff
|
41
|
+
X-Xss-Protection:
|
42
|
+
- 1; mode=block
|
43
|
+
Cache-Control:
|
44
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
45
|
+
Pragma:
|
46
|
+
- no-cache
|
47
|
+
Expires:
|
48
|
+
- '0'
|
49
|
+
X-Powered-By:
|
50
|
+
- HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
|
51
|
+
Access-Control-Allow-Credentials:
|
52
|
+
- 'true'
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: |-
|
56
|
+
http_version:
|
57
|
+
recorded_at: Wed, 05 Apr 2017 12:08:41 GMT
|
58
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://develop.lifen.fr/valid
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.11.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer valid_application_access_token
|
14
|
+
Accept:
|
15
|
+
- application/pdf
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: Success
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.6.2
|
25
|
+
Date:
|
26
|
+
- Wed, 05 Apr 2017 12:08:41 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/xml+fhir;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
X-B3-Sampled:
|
34
|
+
- '1'
|
35
|
+
X-B3-Spanid:
|
36
|
+
- fb30b5b1b27d94fe
|
37
|
+
X-B3-Traceid:
|
38
|
+
- fb30b5b1b27d94fe
|
39
|
+
X-Content-Type-Options:
|
40
|
+
- nosniff
|
41
|
+
X-Xss-Protection:
|
42
|
+
- 1; mode=block
|
43
|
+
Cache-Control:
|
44
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
45
|
+
Pragma:
|
46
|
+
- no-cache
|
47
|
+
Expires:
|
48
|
+
- '0'
|
49
|
+
X-Powered-By:
|
50
|
+
- HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
|
51
|
+
Access-Control-Allow-Credentials:
|
52
|
+
- 'true'
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: |-
|
56
|
+
http_version:
|
57
|
+
recorded_at: Wed, 05 Apr 2017 12:08:41 GMT
|
58
|
+
recorded_with: VCR 3.0.3
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LifenFhir::Logger do
|
4
|
+
|
5
|
+
context "stand alone usage" do
|
6
|
+
it "logs to a given IO" do
|
7
|
+
stringio = StringIO.new
|
8
|
+
log = LifenFhir::Logger.new(stringio)
|
9
|
+
|
10
|
+
log.fatal("Une erreur est survenue")
|
11
|
+
|
12
|
+
expect(stringio.string).to end_with("FATAL -- lifen_fhir: *** [LIFEN] Une erreur est survenue\n")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
context 'client usage' do
|
18
|
+
|
19
|
+
let(:client) { LifenFhir::AppAuthenticatedClient.new }
|
20
|
+
let(:stringio) { StringIO.new }
|
21
|
+
|
22
|
+
before do
|
23
|
+
LifenFhir.configure do |config|
|
24
|
+
config.logger = Logger.new(stringio)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "logs to a given logger" do
|
29
|
+
begin
|
30
|
+
VCR.use_cassette "logger/invalid" do
|
31
|
+
client.get("/invalid")
|
32
|
+
end
|
33
|
+
rescue LifenFhir::Error => e
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(stringio.string).to end_with("FATAL -- : *** [LIFEN] 404 Error on GET 'https://develop.lifen.fr/invalid'\n")
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with a success response' do
|
41
|
+
|
42
|
+
it "logs to a given logger with info level" do
|
43
|
+
VCR.use_cassette "logger/valid" do
|
44
|
+
client.get("/valid")
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(stringio.string).to end_with("INFO -- : *** [LIFEN] Success on GET 'https://develop.lifen.fr/valid'\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifen_fhir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonard Sellam
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-06-
|
12
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -210,6 +210,9 @@ files:
|
|
210
210
|
- lib/lifen_fhir/content_string.rb
|
211
211
|
- lib/lifen_fhir/element.rb
|
212
212
|
- lib/lifen_fhir/error.rb
|
213
|
+
- lib/lifen_fhir/integrations/rails.rb
|
214
|
+
- lib/lifen_fhir/integrations/railties.rb
|
215
|
+
- lib/lifen_fhir/logger.rb
|
213
216
|
- lib/lifen_fhir/medium.rb
|
214
217
|
- lib/lifen_fhir/patient.rb
|
215
218
|
- lib/lifen_fhir/practitioner.rb
|
@@ -231,6 +234,8 @@ files:
|
|
231
234
|
- spec/cassettes/communication_request/send/unknown_recipient.yml
|
232
235
|
- spec/cassettes/communication_request/send/valid_attributes.yml
|
233
236
|
- spec/cassettes/communication_request/send/valid_attributes_binary.yml
|
237
|
+
- spec/cassettes/logger/invalid.yml
|
238
|
+
- spec/cassettes/logger/valid.yml
|
234
239
|
- spec/cassettes/patient/create/invalid_attributes.yml
|
235
240
|
- spec/cassettes/patient/create/with_all_information.yml
|
236
241
|
- spec/cassettes/patient/create/with_first_name_as_a_string.yml
|
@@ -246,6 +251,7 @@ files:
|
|
246
251
|
- spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
|
247
252
|
- spec/category_spec.rb
|
248
253
|
- spec/communication_request_spec.rb
|
254
|
+
- spec/logger_spec.rb
|
249
255
|
- spec/patient_spec.rb
|
250
256
|
- spec/practitioner_spec.rb
|
251
257
|
- spec/reference_spec.rb
|
@@ -290,6 +296,8 @@ test_files:
|
|
290
296
|
- spec/cassettes/communication_request/send/unknown_recipient.yml
|
291
297
|
- spec/cassettes/communication_request/send/valid_attributes.yml
|
292
298
|
- spec/cassettes/communication_request/send/valid_attributes_binary.yml
|
299
|
+
- spec/cassettes/logger/invalid.yml
|
300
|
+
- spec/cassettes/logger/valid.yml
|
293
301
|
- spec/cassettes/patient/create/invalid_attributes.yml
|
294
302
|
- spec/cassettes/patient/create/with_all_information.yml
|
295
303
|
- spec/cassettes/patient/create/with_first_name_as_a_string.yml
|
@@ -305,6 +313,7 @@ test_files:
|
|
305
313
|
- spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
|
306
314
|
- spec/category_spec.rb
|
307
315
|
- spec/communication_request_spec.rb
|
316
|
+
- spec/logger_spec.rb
|
308
317
|
- spec/patient_spec.rb
|
309
318
|
- spec/practitioner_spec.rb
|
310
319
|
- spec/reference_spec.rb
|