lifen-fhir 0.1.0

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +74 -0
  8. data/License.txt +22 -0
  9. data/README.md +131 -0
  10. data/lib/lifen.rb +29 -0
  11. data/lib/lifen/app_authenticated_client.rb +37 -0
  12. data/lib/lifen/attachment.rb +26 -0
  13. data/lib/lifen/base.rb +7 -0
  14. data/lib/lifen/binary.rb +31 -0
  15. data/lib/lifen/category.rb +26 -0
  16. data/lib/lifen/channel.rb +31 -0
  17. data/lib/lifen/client.rb +107 -0
  18. data/lib/lifen/communication_request.rb +67 -0
  19. data/lib/lifen/configuration.rb +22 -0
  20. data/lib/lifen/content_string.rb +15 -0
  21. data/lib/lifen/error.rb +27 -0
  22. data/lib/lifen/medium.rb +17 -0
  23. data/lib/lifen/patient.rb +27 -0
  24. data/lib/lifen/practitioner.rb +97 -0
  25. data/lib/lifen/user_authenticated_client.rb +39 -0
  26. data/lib/lifen/version.rb +3 -0
  27. data/lifen-fhir.gemspec +30 -0
  28. data/spec/binary_spec.rb +29 -0
  29. data/spec/cassettes/binary/download/invalid.yml +65 -0
  30. data/spec/cassettes/binary/download/valid.yml +1320 -0
  31. data/spec/cassettes/communication_request/send/invalid_medium.yml +69 -0
  32. data/spec/cassettes/communication_request/send/valid_attributes.yml +75 -0
  33. data/spec/cassettes/communication_request/send/valid_attributes_binary.yml +74 -0
  34. data/spec/cassettes/practitionner/create_channel/address/old_valid_attributes.yml +71 -0
  35. data/spec/cassettes/practitionner/create_channel/address/valid_attributes.yml +71 -0
  36. data/spec/cassettes/practitionner/create_channel/telecom/valid_attributes.yml +70 -0
  37. data/spec/cassettes/practitionner/find_by_rpps/existing_rpps.yml +125 -0
  38. data/spec/cassettes/practitionner/find_by_rpps/missing_line_attribute.yml +122 -0
  39. data/spec/cassettes/practitionner/find_by_rpps/wrong_rpps.yml +68 -0
  40. data/spec/category_spec.rb +21 -0
  41. data/spec/communication_request_spec.rb +64 -0
  42. data/spec/practitionner_spec.rb +76 -0
  43. data/spec/spec_helper.rb +24 -0
  44. data/spec/support/master_plan.pdf +0 -0
  45. metadata +230 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59562c836fd00fe186bd7a80c426c9a04de67450
4
+ data.tar.gz: cdd6c4a303f5af5d9649c0bf2945ed30c0d1758f
5
+ SHA512:
6
+ metadata.gz: d892166f3d655146c8eea87e9368608e4706795f93cbef9103151bfef799e28a1f68eb218a62f96380485385974f96c7155b76d8b5b336605d72ebc9de5958ff
7
+ data.tar.gz: faa32a8f504e12a7eb5191803094458b709a1428dc1c76350ed5b6d853fdcb75585423b25448e0288dc7539f60c91ad10ec621d921a3c9f6ee140e80e528fd7d
@@ -0,0 +1,17 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -0,0 +1,4 @@
1
+ 0.1.0
2
+ -----
3
+
4
+ - Lifen is on FHIR !
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lifen-fhir (0.1.0)
5
+ faraday (>= 0.9)
6
+ inflecto
7
+ virtus (>= 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.1)
13
+ public_suffix (~> 2.0, >= 2.0.2)
14
+ awesome_print (1.7.0)
15
+ axiom-types (0.1.1)
16
+ descendants_tracker (~> 0.0.4)
17
+ ice_nine (~> 0.11.0)
18
+ thread_safe (~> 0.3, >= 0.3.1)
19
+ coercible (1.0.0)
20
+ descendants_tracker (~> 0.0.1)
21
+ crack (0.4.3)
22
+ safe_yaml (~> 1.0.0)
23
+ descendants_tracker (0.0.4)
24
+ thread_safe (~> 0.3, >= 0.3.1)
25
+ diff-lcs (1.3)
26
+ equalizer (0.0.11)
27
+ faraday (0.12.1)
28
+ multipart-post (>= 1.2, < 3)
29
+ hashdiff (0.3.4)
30
+ ice_nine (0.11.2)
31
+ inflecto (0.0.2)
32
+ multipart-post (2.0.0)
33
+ public_suffix (2.0.5)
34
+ rake (10.5.0)
35
+ rspec (3.6.0)
36
+ rspec-core (~> 3.6.0)
37
+ rspec-expectations (~> 3.6.0)
38
+ rspec-mocks (~> 3.6.0)
39
+ rspec-core (3.6.0)
40
+ rspec-support (~> 3.6.0)
41
+ rspec-expectations (3.6.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.6.0)
44
+ rspec-mocks (3.6.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.6.0)
47
+ rspec-support (3.6.0)
48
+ safe_yaml (1.0.4)
49
+ thread_safe (0.3.6)
50
+ vcr (3.0.3)
51
+ virtus (1.0.5)
52
+ axiom-types (~> 0.1)
53
+ coercible (~> 1.0)
54
+ descendants_tracker (~> 0.0, >= 0.0.3)
55
+ equalizer (~> 0.0, >= 0.0.9)
56
+ webmock (1.24.6)
57
+ addressable (>= 2.3.6)
58
+ crack (>= 0.3.2)
59
+ hashdiff
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ awesome_print
66
+ bundler (~> 1.12)
67
+ lifen-fhir!
68
+ rake (~> 10.5)
69
+ rspec (~> 3.5)
70
+ vcr (~> 3.0)
71
+ webmock (~> 1.24)
72
+
73
+ BUNDLED WITH
74
+ 1.14.6
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Honestica
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,131 @@
1
+ # Lifen
2
+
3
+ Lifen is a Ruby client for [Lifen](http://developers.lifen.fr/) FHIR API (over JSON).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lifen-fhir'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lifen-fhir
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+
25
+ Lifen can be configured (ideally inside an initializer) like so:
26
+
27
+ ```ruby
28
+ Lifen.configure do |config|
29
+ config.site = "https://demo.lifen.fr/"
30
+ config.application_access_token = "application_access_token"
31
+
32
+ # optionnal
33
+ config.proxy_url = "http://my.proxy.fr/"
34
+ end
35
+ ```
36
+
37
+ Optionnal configuration:
38
+
39
+ - `proxy_url`: enables you to route all your requests via a proxy
40
+
41
+ ### Internal
42
+
43
+ #### Managing a Binary
44
+
45
+ ```ruby
46
+ binary = Lifen::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
47
+ binary.download
48
+ ```
49
+
50
+ ### Communication Request
51
+
52
+ ```ruby
53
+ sender = Lifen::Practitioner.find_by_rpps("899900018483")
54
+
55
+ recipient = Lifen::Practitioner.find_by_rpps("899900018484")
56
+ channel = recipient.channels.first
57
+
58
+ binary = Lifen::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
59
+
60
+ communication_request = Lifen::CommunicationRequest.new(sender: sender, recipient: recipient, channel: channel, binary: binary, patient: patient, category: category)
61
+
62
+ communication_request.send
63
+
64
+ ```
65
+
66
+ #### Communication Request with multiple recipients
67
+
68
+ ```ruby
69
+ sender = Lifen::Practitioner.find_by_rpps("899900018483")
70
+
71
+ recipient = Lifen::Practitioner.find_by_rpps("899900018484")
72
+ medium = Lifen::Medium(uuid: recipient.channels.first.uuid)
73
+
74
+ other_recipient = Lifen::Practitioner.find_by_rpps("899900018484")
75
+ other_medium = Lifen::Medium(uuid: other_recipient.channels.first.uuid)
76
+
77
+ binary = Lifen::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
78
+
79
+ communication_request_request = Lifen::CommunicationRequest.new(sender: sender, recipients: [recipient, other_recipient], medium: [medium, other_medium], binary: binary, patient: patient, category: category)
80
+
81
+ communication_request_request.send
82
+
83
+ ```
84
+
85
+ #### Custom Channels management
86
+
87
+ ```ruby
88
+ recipient = Lifen::Practitioner.new(uuid: "valid-user-uuid")
89
+
90
+ # To create a new mailing address channel
91
+ channel = recipient.create_address(type: "address", lines: ["39 rue Aboukir"], city: "Paris", postal_code: "75002", country: "France")
92
+
93
+ # To create a new telecom channel fax
94
+ channel = recipient.create_telecom(type: "telecom", system: "fax", value: "+33102030405")
95
+ ```
96
+
97
+ ## Deploying to Rubygems
98
+
99
+ Once the new version is validated, the deployment follows those steps :
100
+
101
+ 1. update `lib/lifen/version.rb`
102
+ 2. run `bundle install` to update `Gemfile.lock`
103
+ 3. update `CHANGELOG.md` with the additional features of the new version
104
+ 4. commit changes to Github
105
+ 5. build the gem using `gem build lifen-fhir.gemspec`
106
+ 6. publish the gem using `gem publish lifen-fhir-X.X.X.gem`
107
+ 7. run `bundle update lifen` in related projects :)
108
+
109
+ ## License
110
+
111
+ The MIT License (MIT)
112
+
113
+ Copyright (c) 2016-2017 Honestica
114
+
115
+ Permission is hereby granted, free of charge, to any person obtaining a copy
116
+ of this software and associated documentation files (the "Software"), to deal
117
+ in the Software without restriction, including without limitation the rights
118
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
119
+ copies of the Software, and to permit persons to whom the Software is
120
+ furnished to do so, subject to the following conditions:
121
+
122
+ The above copyright notice and this permission notice shall be included in
123
+ all copies or substantial portions of the Software.
124
+
125
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
126
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
127
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
128
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
129
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
130
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
131
+ THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ module Lifen
2
+
3
+ require 'virtus'
4
+ require 'faraday'
5
+ require 'inflecto'
6
+ require 'base64'
7
+
8
+ require "lifen/version"
9
+
10
+ require 'lifen/error'
11
+ require 'lifen/client'
12
+ require 'lifen/user_authenticated_client'
13
+ require 'lifen/app_authenticated_client'
14
+ require 'lifen/configuration'
15
+ require 'lifen/base'
16
+
17
+ require 'lifen/channel'
18
+ require 'lifen/practitioner'
19
+ require 'lifen/category'
20
+ require 'lifen/medium'
21
+ require 'lifen/attachment'
22
+ require 'lifen/binary'
23
+ require 'lifen/patient'
24
+ require 'lifen/content_string'
25
+ require 'lifen/communication_request'
26
+
27
+ Virtus.finalize
28
+
29
+ end
@@ -0,0 +1,37 @@
1
+ module Lifen
2
+ class AppAuthenticatedClient < Client
3
+
4
+ private
5
+
6
+ def handle_errors(response, params)
7
+ super(response, params)
8
+
9
+ case response.status
10
+ when 400
11
+ raise Error, "Error 400, Unknown error, #{response_error(response, params)}"
12
+ when 401
13
+ raise InvalidSecretTokenError, "Error 401, Invalid app bearer, #{response_error(response, params)}"
14
+ when 403
15
+ raise UserAlreadyExistingError, "Error 403, User already existing, #{response_error(response, params)}"
16
+ when 404
17
+ raise Error, "Error 404, Page not found, #{response_error(response, params)}"
18
+ when 422
19
+ json = JSON.parse response.body
20
+
21
+ diagnostic = json["issue"][0]["diagnostics"]
22
+
23
+ raise Error, "Error 422, Unprocessable Entity, Diagnostic: '#{diagnostic}', #{response_error(response, params)}"
24
+ end
25
+
26
+ end
27
+
28
+ def response_error(response, params)
29
+ "App Client, #{super(response, params)}"
30
+ end
31
+
32
+ def bearer
33
+ Lifen.configuration.application_access_token
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ module Lifen
2
+
3
+ class Attachment < Base
4
+
5
+ attribute :title, String
6
+ attribute :path, String
7
+ attribute :content_type, String
8
+
9
+ def fhir_payload
10
+ {
11
+ contentAttachment: {
12
+ data: base_64_encoded_content,
13
+ title: title,
14
+ contentType: "{#{content_type}}"
15
+ }
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def base_64_encoded_content
22
+ Base64.encode64(File.open(path, "rb").read)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Lifen
2
+ class Base
3
+
4
+ include Virtus.model
5
+
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+
2
+ module Lifen
3
+
4
+ class Binary < Base
5
+
6
+ attribute :uuid, String
7
+
8
+ def fhir_payload
9
+ {
10
+ contentReference: {
11
+ reference: reference
12
+ }
13
+ }
14
+ end
15
+
16
+ def download
17
+ application_client.get("fhir/#{reference}", { accept: "application/pdf" })
18
+ end
19
+
20
+ private
21
+
22
+ def application_client
23
+ @application_client ||= AppAuthenticatedClient.new
24
+ end
25
+
26
+ def reference
27
+ "Binary/#{uuid}"
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module Lifen
2
+ class Category < Base
3
+
4
+ CODES = ["MEDICAL_REPORT", "MESSAGE", "MEDICATION_ORDER", "REFERRAL_REQUEST", "OTHER"]
5
+
6
+ attribute :code, String, default: "MEDICAL_REPORT"
7
+
8
+ def fhir_payload
9
+ raise Lifen::Error, "Invalid category: code must be in the authorized values" if !valid?
10
+
11
+ {
12
+ coding: [
13
+ {
14
+ system: "http://honestica.com/fhir/communication/category",
15
+ code: code
16
+ }
17
+ ]
18
+ }
19
+ end
20
+
21
+ def valid?
22
+ CODES.include? code
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Lifen
2
+ class Channel < Base
3
+
4
+ attribute :uuid, String
5
+ attribute :type, String
6
+ attribute :value, String
7
+
8
+ def fhir_payload(user)
9
+ raise Lifen::Error, "Invalid channel: an UUID is required" if !valid?
10
+
11
+ {
12
+ id: user.uuid,
13
+ resourceType: "Practitioner",
14
+ type => [
15
+ {
16
+ id: uuid
17
+ }
18
+ ]
19
+ }
20
+ end
21
+
22
+ def valid?
23
+ uuid and uuid.length != 0
24
+ end
25
+
26
+ def self.from_json(json, type = nil)
27
+ new(uuid: json["id"], type: type, value: json["value"] || "#{Array(json["line"]).join(", ")}, #{json["postalCode"]} #{json["city"]}")
28
+ end
29
+
30
+ end
31
+ end