lifen 1.6.8 → 2.0.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: a3d322a8bc4f1c194166d375f02116f0ac2cbe8e
4
- data.tar.gz: b8e31970ddbdca6c158ee313c4405b0f7340f2e9
3
+ metadata.gz: 9a170e3ecea4b77de29a7e3f1d43b07d326f75c0
4
+ data.tar.gz: 655170fca70cedd95108e8f4ddd70aa09a31777d
5
5
  SHA512:
6
- metadata.gz: 961fe51d9c3518abc4ed8372d250ec1df9a5f3b3ad75942a04609ddb6f8935050faa67b083c15585b33c9b5cb5f7736017d90e8ff9ec795d825b591014b6453e
7
- data.tar.gz: f3ae94a202cc841fda0abe90f5b3a1147076232d82d6ef115ce6f0b7bfee1d4bd05334ee5b286ebe5fd6b07972fa6a7ecf4bb349320fdf2c2eff2a2f74538860
6
+ metadata.gz: ab0ea57784dae76f2289b0a5a99769d5ced3f9ae50394fcd0ecae836c5b589460b88919d85b34d6f976466cbdebe9d7501fc57ce0ed30375dc50ab87fc43efde
7
+ data.tar.gz: 3c2446fdfb4a54af5fe4f670e54446d75e3ebd00e77b206d42b211128d77c5b70b585a62d5168ead5be95fe087f94531361fed5ebabfe424dfe3a6a279de20bf
@@ -1,3 +1,10 @@
1
+ 2.0.0
2
+ -----
3
+
4
+ - Major refactoring on objects to better manage Communications
5
+ - Added the possibility to select a Category
6
+ - Added the possibility to find a Communication
7
+
1
8
  1.6.8
2
9
  -----
3
10
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen (1.6.8)
4
+ lifen (2.0.0)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
data/README.md CHANGED
@@ -126,7 +126,7 @@ message = Lifen::Message.new(flow: flow, content: "Hello World !")
126
126
  message.create
127
127
  ```
128
128
 
129
- ### Communication requests (FHIR)
129
+ ### Communications (FHIR)
130
130
 
131
131
  ```ruby
132
132
  sender = Lifen::User.find_by_rpps("899900018483")
@@ -134,12 +134,17 @@ sender = Lifen::User.find_by_rpps("899900018483")
134
134
  recipient = Lifen::User.find_by_rpps("899900018484")
135
135
  channel = recipient.channels.first
136
136
 
137
- attachment = Lifen::Communication::Attachment.new(title: "Test document", path: "path/to/file")
137
+ category = Lifen::Category.new(code: "MEDICAL_REPORT") # default case, optionnal element
138
138
 
139
- patient = Lifen::Communication::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1))
139
+ attachment = Lifen::Attachment.new(title: "Test document", path: "path/to/file")
140
140
 
141
- request = Lifen::Communication::Request.new(sender: sender, recipient: recipient, channel: channel, attachment: attachment, patient: patient)
142
- request.send
141
+ patient = Lifen::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1))
142
+
143
+ communication = Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, attachment: attachment, patient: patient, category: category)
144
+ communication.send
145
+
146
+ communication = Lifen::Communication.find("valid-communication-uuid")
147
+ communication.status
143
148
  ```
144
149
 
145
150
  ### Custom Addresses management
@@ -22,12 +22,11 @@ module Lifen
22
22
  require 'lifen/flows'
23
23
  require 'lifen/message'
24
24
 
25
- require 'lifen/communication/attachment'
26
- require 'lifen/communication/channel'
27
- require 'lifen/communication/patient'
28
- require 'lifen/communication/request'
29
-
30
-
25
+ require 'lifen/category'
26
+ require 'lifen/attachment'
27
+ require 'lifen/channel'
28
+ require 'lifen/patient'
29
+ require 'lifen/communication'
31
30
 
32
31
  Virtus.finalize
33
32
 
@@ -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,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
@@ -0,0 +1,77 @@
1
+ module Lifen
2
+ class Communication < Base
3
+
4
+ attribute :uuid, String
5
+
6
+ attribute :sender, Lifen::User
7
+ attribute :recipient, Lifen::User
8
+
9
+ attribute :category, Lifen::Category, default: Lifen::Category.new
10
+ attribute :channel, Lifen::Channel
11
+ attribute :patient, Lifen::Patient
12
+ attribute :attachment, Lifen::Attachment
13
+
14
+ attribute :status, String
15
+ attribute :sent_at, DateTime
16
+ attribute :received_at, DateTime
17
+
18
+ def send
19
+ json = application_client.post("fhir/CommunicationRequest", fhir_payload)
20
+
21
+ self.uuid = json["id"]
22
+
23
+ self
24
+ end
25
+
26
+ def self.find(uuid)
27
+ json = application_client.get("fhir/Communication/#{uuid}")
28
+
29
+ resource_type = json["resourceType"]
30
+
31
+ raise Error, "Invalid resourceType (#{resource_type})" if resource_type != "Communication"
32
+
33
+ attributes = {}
34
+
35
+ attributes[:uuid] = json["id"]
36
+ attributes[:status] = json["status"]
37
+ attributes[:sent_at] = json["sent"]
38
+ attributes[:received_at] = json["received"]
39
+
40
+ attributes[:sender] = User.from_json(json["sender"])
41
+ attributes[:recipient] = User.from_json(Array(json["recipient"]).first)
42
+
43
+ new(attributes)
44
+ end
45
+
46
+ private
47
+
48
+ def fhir_payload
49
+ payload = {
50
+ resourceType: "CommunicationRequest",
51
+ sender: [ sender.fhir_payload ],
52
+ recipient: [ recipient.fhir_payload ],
53
+ contained: [ channel.fhir_payload(recipient) ],
54
+ category: [ category.fhir_payload],
55
+ payload: [ attachment.fhir_payload ],
56
+ }
57
+
58
+ if patient
59
+ payload[:contained] << patient.fhir_payload
60
+ payload[:subject] = [
61
+ {reference: "patient"}
62
+ ]
63
+ end
64
+
65
+ payload
66
+ end
67
+
68
+ def application_client
69
+ @application_client ||= AppAuthenticatedClient.new
70
+ end
71
+
72
+ def self.application_client
73
+ @application_client ||= AppAuthenticatedClient.new
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,27 @@
1
+ module Lifen
2
+ class Patient < Base
3
+
4
+ attribute :first_name, String
5
+ attribute :last_name, String
6
+ attribute :birthdate, Date
7
+
8
+ def fhir_payload
9
+ {
10
+ id: "patient",
11
+ resourceType: "Patient",
12
+ name: [
13
+ {
14
+ family: [
15
+ last_name
16
+ ],
17
+ given: [
18
+ first_name
19
+ ]
20
+ }
21
+ ],
22
+ birthDate: birthdate.to_s
23
+ }
24
+ end
25
+
26
+ end
27
+ end
@@ -5,7 +5,7 @@ module Lifen
5
5
  attribute :token, "Lifen::Token"
6
6
  attribute :status, "Lifen::Status"
7
7
  attribute :settings, "Lifen::Settings"
8
- attribute :channels, ["Lifen::Communication::Channel"]
8
+ attribute :channels, ["Lifen::Channel"]
9
9
 
10
10
  attribute :uuid, String
11
11
  attribute :email, String
@@ -128,11 +128,11 @@ module Lifen
128
128
  user = new(user_json)
129
129
 
130
130
  Array(user_json["telecom"]).each do |telecom_json|
131
- user.channels << Lifen::Communication::Channel.from_json(telecom_json, "telecom")
131
+ user.channels << Lifen::Channel.from_json(telecom_json, "telecom")
132
132
  end
133
133
 
134
134
  Array(user_json["address"]).each do |address_json|
135
- user.channels << Lifen::Communication::Channel.from_json(address_json, "address")
135
+ user.channels << Lifen::Channel.from_json(address_json, "address")
136
136
  end
137
137
 
138
138
  user
@@ -152,13 +152,21 @@ module Lifen
152
152
 
153
153
  json = application_client.post("fhir/Practitioner/#{uuid}/$add-address", filtered_params)
154
154
 
155
- channel = Communication::Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: "#{Array(params[:lines]).join(", ")}, #{params[:postal_code]} #{params[:city]}")
155
+ channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: "#{Array(params[:lines]).join(", ")}, #{params[:postal_code]} #{params[:city]}")
156
156
 
157
157
  self.channels << channel
158
158
 
159
159
  channel
160
160
  end
161
161
 
162
+ def self.from_json(json)
163
+ reference = json["reference"]
164
+
165
+ uuid = reference.gsub("Practitioner/", "")
166
+
167
+ new(uuid: uuid)
168
+ end
169
+
162
170
  private
163
171
 
164
172
  def application_client
@@ -1,3 +1,3 @@
1
1
  module Lifen
2
- VERSION = "1.6.8"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -0,0 +1,70 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/invalid-communication-uuid
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
+ Content-Type:
15
+ - application/json
16
+ Accept:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: Not Found
24
+ headers:
25
+ Server:
26
+ - Apache-Coyote/1.1
27
+ X-B3-Sampled:
28
+ - '1'
29
+ X-B3-Spanid:
30
+ - 8a19efd4d9012fbd
31
+ X-B3-Traceid:
32
+ - 8a19efd4d9012fbd
33
+ X-Content-Type-Options:
34
+ - nosniff
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Cache-Control:
38
+ - no-cache, no-store, max-age=0, must-revalidate
39
+ Pragma:
40
+ - no-cache
41
+ Expires:
42
+ - '0'
43
+ X-Powered-By:
44
+ - HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
45
+ Content-Type:
46
+ - application/json+fhir;charset=UTF-8
47
+ Transfer-Encoding:
48
+ - chunked
49
+ Date:
50
+ - Fri, 24 Mar 2017 09:37:43 GMT
51
+ Connection:
52
+ - close
53
+ Access-Control-Allow-Credentials:
54
+ - 'true'
55
+ body:
56
+ encoding: UTF-8
57
+ string: |-
58
+ {
59
+ "resourceType": "OperationOutcome",
60
+ "issue": [
61
+ {
62
+ "severity": "error",
63
+ "code": "not-found",
64
+ "diagnostics": "Unknown Resource id=invalid-communication-uuid"
65
+ }
66
+ ]
67
+ }
68
+ http_version:
69
+ recorded_at: Fri, 24 Mar 2017 09:37:43 GMT
70
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,96 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/11e71070-15f9-23c1-9ad2-0242ac110002
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
+ Content-Type:
15
+ - application/json
16
+ Accept:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Apache-Coyote/1.1
27
+ X-B3-Sampled:
28
+ - '1'
29
+ X-B3-Spanid:
30
+ - e3501c29e536dd60
31
+ X-B3-Traceid:
32
+ - e3501c29e536dd60
33
+ X-Content-Type-Options:
34
+ - nosniff
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Cache-Control:
38
+ - no-cache, no-store, max-age=0, must-revalidate
39
+ Pragma:
40
+ - no-cache
41
+ Expires:
42
+ - '0'
43
+ X-Powered-By:
44
+ - HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
45
+ Content-Location:
46
+ - http://develop.lifen.fr/fhir/Communication/11e71070-15f9-23c1-9ad2-0242ac110002
47
+ Location:
48
+ - http://develop.lifen.fr/fhir/Communication/11e71070-15f9-23c1-9ad2-0242ac110002
49
+ Content-Type:
50
+ - application/json+fhir;charset=UTF-8
51
+ Transfer-Encoding:
52
+ - chunked
53
+ Date:
54
+ - Fri, 24 Mar 2017 09:35:35 GMT
55
+ Connection:
56
+ - close
57
+ Access-Control-Allow-Credentials:
58
+ - 'true'
59
+ body:
60
+ encoding: UTF-8
61
+ string: |-
62
+ {
63
+ "resourceType": "Communication",
64
+ "id": "11e71070-15f9-23c1-9ad2-0242ac110002",
65
+ "sender": {
66
+ "reference": "Practitioner/11e5b841-4ff1-2dbb-9643-eabb809fa654"
67
+ },
68
+ "recipient": [
69
+ {
70
+ "reference": "Practitioner/11e5c866-a698-cfb0-9b29-deb9993a92c0"
71
+ }
72
+ ],
73
+ "payload": [
74
+ {
75
+ "contentReference": {
76
+ "reference": "11e71070-15f3-5755-9ad2-0242ac110002"
77
+ }
78
+ }
79
+ ],
80
+ "medium": [
81
+ {
82
+ "coding": [
83
+ {
84
+ "system": "http://honestica.com/fhir/channel",
85
+ "code": "APICRYPT"
86
+ }
87
+ ]
88
+ }
89
+ ],
90
+ "status": "completed",
91
+ "sent": "2017-03-24T08:58:45+00:00",
92
+ "received": "2017-03-24T08:58:44+00:00"
93
+ }
94
+ http_version:
95
+ recorded_at: Fri, 24 Mar 2017 09:35:35 GMT
96
+ recorded_with: VCR 3.0.3
@@ -68,12 +68,12 @@ http_interactions:
68
68
  "link": [
69
69
  {
70
70
  "relation": "self",
71
- "url": "http://demo.lifen.fr/public-api/fhir/Practitioner/?identifier=810004085790"
71
+ "url": "http://develop.lifen.fr/public-api/fhir/Practitioner/?identifier=810004085790"
72
72
  }
73
73
  ],
74
74
  "entry": [
75
75
  {
76
- "fullUrl": "http://demo.lifen.fr/public-api/fhir/Practitioner/11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
76
+ "fullUrl": "http://develop.lifen.fr/public-api/fhir/Practitioner/11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
77
77
  "resource": {
78
78
  "resourceType": "Practitioner",
79
79
  "id": "11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
@@ -68,12 +68,12 @@ http_interactions:
68
68
  "link": [
69
69
  {
70
70
  "relation": "self",
71
- "url": "http://demo.lifen.fr/public-api/fhir/Practitioner/?identifier=810004085790"
71
+ "url": "http://develop.lifen.fr/public-api/fhir/Practitioner/?identifier=810004085790"
72
72
  }
73
73
  ],
74
74
  "entry": [
75
75
  {
76
- "fullUrl": "http://demo.lifen.fr/public-api/fhir/Practitioner/11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
76
+ "fullUrl": "http://develop.lifen.fr/public-api/fhir/Practitioner/11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
77
77
  "resource": {
78
78
  "resourceType": "Practitioner",
79
79
  "id": "11e5c86b-e4ba-eee4-9b29-deb9993a92c0",
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lifen::Category do
4
+
5
+ let(:category) { Lifen::Category.new }
6
+
7
+ describe ':valid?' do
8
+
9
+ it 'default case is valid' do
10
+ expect(category).to be_valid
11
+ end
12
+
13
+ it 'unknown case is not valid' do
14
+ category.code = "UNKOWN CODE"
15
+
16
+ expect(category).to_not be_valid
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lifen::Communication do
4
+
5
+ let(:channel) { Lifen::Channel.new(uuid: "valid_channel_uuid", type: "address") } #valid_channel_uuid
6
+
7
+ let(:sender) { Lifen::User.new(uuid: "valid_sender_uuid") } #valid_sender_uuid
8
+ let(:recipient) { Lifen::User.new(uuid: "valid_recipient_uuid") } #valid_recipient_uuid
9
+
10
+ let(:attachment) { Lifen::Attachment.new(title: "Master Plan", path: File.dirname(__FILE__) + "/support/master_plan.pdf", content_type: "application/pdf") }
11
+
12
+ let(:patient) { Lifen::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1)) }
13
+
14
+
15
+ describe ':send' do
16
+
17
+ let(:communication) { Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, attachment: attachment, patient: patient) }
18
+
19
+ it 'works' do
20
+ VCR.use_cassette "communication/send/valid_attributes" do
21
+ communication.send
22
+ end
23
+
24
+ expect(communication.uuid).to_not be_nil
25
+ end
26
+
27
+ context 'invalid channel' do
28
+
29
+ let(:channel) { Lifen::Channel.new(uuid: nil) }
30
+
31
+ it 'raises an error' do
32
+ expect{
33
+ communication.send
34
+ }.to raise_error Lifen::Error, "Invalid channel: an UUID is required"
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ describe ':find' do
42
+
43
+ it 'works' do
44
+ VCR.use_cassette "communication/find/valid_uuid" do
45
+ @communication = Lifen::Communication.find "11e71070-15f9-23c1-9ad2-0242ac110002"
46
+ end
47
+
48
+ expect(@communication.status).to eq "completed"
49
+ expect(@communication.uuid).to eq "11e71070-15f9-23c1-9ad2-0242ac110002"
50
+
51
+ expect(@communication.sent_at).to eq DateTime.new(2017,3,24,8,58,45)
52
+ expect(@communication.received_at).to eq DateTime.new(2017,3,24,8,58,44)
53
+
54
+ expect(@communication.sender.uuid).to eq "11e5b841-4ff1-2dbb-9643-eabb809fa654"
55
+ expect(@communication.recipient.uuid).to eq "11e5c866-a698-cfb0-9b29-deb9993a92c0"
56
+
57
+ end
58
+
59
+ context 'invalid uuid' do
60
+
61
+ it 'raises an error' do
62
+ VCR.use_cassette "communication/find/invalid_uuid" do
63
+ expect{
64
+ Lifen::Communication.find "invalid-communication-uuid"
65
+ }.to raise_error Lifen::Error, "Error 404, Page not found, App Client, GET 'https://develop.lifen.fr/fhir/Communication/invalid-communication-uuid' with params '{}' and bearer 'valid_application_access******'"
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Etienne Depaulis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,17 +154,18 @@ files:
154
154
  - Rakefile
155
155
  - lib/lifen.rb
156
156
  - lib/lifen/app_authenticated_client.rb
157
+ - lib/lifen/attachment.rb
157
158
  - lib/lifen/base.rb
159
+ - lib/lifen/category.rb
160
+ - lib/lifen/channel.rb
158
161
  - lib/lifen/client.rb
159
- - lib/lifen/communication/attachment.rb
160
- - lib/lifen/communication/channel.rb
161
- - lib/lifen/communication/patient.rb
162
- - lib/lifen/communication/request.rb
162
+ - lib/lifen/communication.rb
163
163
  - lib/lifen/configuration.rb
164
164
  - lib/lifen/error.rb
165
165
  - lib/lifen/flow.rb
166
166
  - lib/lifen/flows.rb
167
167
  - lib/lifen/message.rb
168
+ - lib/lifen/patient.rb
168
169
  - lib/lifen/settings.rb
169
170
  - lib/lifen/status.rb
170
171
  - lib/lifen/token.rb
@@ -172,6 +173,9 @@ files:
172
173
  - lib/lifen/user_authenticated_client.rb
173
174
  - lib/lifen/version.rb
174
175
  - lifen.gemspec
176
+ - spec/cassettes/communication/find/invalid_uuid.yml
177
+ - spec/cassettes/communication/find/valid_uuid.yml
178
+ - spec/cassettes/communication/send/valid_attributes.yml
175
179
  - spec/cassettes/flows/attach_users/invalid_flow_uuid.yml
176
180
  - spec/cassettes/flows/attach_users/invalid_user_uuid.yml
177
181
  - spec/cassettes/flows/attach_users/valid.yml
@@ -184,8 +188,6 @@ files:
184
188
  - spec/cassettes/flows/update_valid_title.yml
185
189
  - spec/cassettes/flows/valid_token.yml
186
190
  - spec/cassettes/messages/valid_message.yml
187
- - spec/cassettes/request/send/error.yml
188
- - spec/cassettes/request/send/valid_attributes.yml
189
191
  - spec/cassettes/settings/initial_state.yml
190
192
  - spec/cassettes/settings/reload.yml
191
193
  - spec/cassettes/settings/update.yml
@@ -204,15 +206,16 @@ files:
204
206
  - spec/cassettes/users/status/reload/valid_token.yml
205
207
  - spec/cassettes/users/token/refresh/invalid_user_uuid.yml
206
208
  - spec/cassettes/users/token/refresh/valid_user_uuid.yml
209
+ - spec/category_spec.rb
210
+ - spec/communication_spec.rb
207
211
  - spec/configuration_spec.rb
208
- - spec/flows_spec.rb
209
- - spec/messages_spec.rb
210
- - spec/requests_spec.rb
212
+ - spec/flow_spec.rb
213
+ - spec/message_spec.rb
211
214
  - spec/settings_spec.rb
212
215
  - spec/spec_helper.rb
213
216
  - spec/support/master_plan.pdf
214
217
  - spec/token_spec.rb
215
- - spec/users_spec.rb
218
+ - spec/user_spec.rb
216
219
  homepage: https://github.com/honestica/lifen
217
220
  licenses:
218
221
  - MIT
@@ -238,6 +241,9 @@ signing_key:
238
241
  specification_version: 4
239
242
  summary: Lifen JSON API ruby client
240
243
  test_files:
244
+ - spec/cassettes/communication/find/invalid_uuid.yml
245
+ - spec/cassettes/communication/find/valid_uuid.yml
246
+ - spec/cassettes/communication/send/valid_attributes.yml
241
247
  - spec/cassettes/flows/attach_users/invalid_flow_uuid.yml
242
248
  - spec/cassettes/flows/attach_users/invalid_user_uuid.yml
243
249
  - spec/cassettes/flows/attach_users/valid.yml
@@ -250,8 +256,6 @@ test_files:
250
256
  - spec/cassettes/flows/update_valid_title.yml
251
257
  - spec/cassettes/flows/valid_token.yml
252
258
  - spec/cassettes/messages/valid_message.yml
253
- - spec/cassettes/request/send/error.yml
254
- - spec/cassettes/request/send/valid_attributes.yml
255
259
  - spec/cassettes/settings/initial_state.yml
256
260
  - spec/cassettes/settings/reload.yml
257
261
  - spec/cassettes/settings/update.yml
@@ -270,12 +274,13 @@ test_files:
270
274
  - spec/cassettes/users/status/reload/valid_token.yml
271
275
  - spec/cassettes/users/token/refresh/invalid_user_uuid.yml
272
276
  - spec/cassettes/users/token/refresh/valid_user_uuid.yml
277
+ - spec/category_spec.rb
278
+ - spec/communication_spec.rb
273
279
  - spec/configuration_spec.rb
274
- - spec/flows_spec.rb
275
- - spec/messages_spec.rb
276
- - spec/requests_spec.rb
280
+ - spec/flow_spec.rb
281
+ - spec/message_spec.rb
277
282
  - spec/settings_spec.rb
278
283
  - spec/spec_helper.rb
279
284
  - spec/support/master_plan.pdf
280
285
  - spec/token_spec.rb
281
- - spec/users_spec.rb
286
+ - spec/user_spec.rb
@@ -1,27 +0,0 @@
1
- module Lifen
2
- module Communication
3
- class Attachment < Lifen::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
27
- end
@@ -1,33 +0,0 @@
1
- module Lifen
2
- module Communication
3
- class Channel < Lifen::Base
4
-
5
- attribute :uuid, String
6
- attribute :type, String
7
- attribute :value, String
8
-
9
- def fhir_payload(user)
10
- raise Lifen::Error, "Invalid channel: an UUID is required" if !valid?
11
-
12
- {
13
- id: user.uuid,
14
- resourceType: "Practitioner",
15
- type => [
16
- {
17
- id: uuid
18
- }
19
- ]
20
- }
21
- end
22
-
23
- def valid?
24
- uuid and uuid.length != 0
25
- end
26
-
27
- def self.from_json(json, type = nil)
28
- new(uuid: json["id"], type: type, value: json["value"] || "#{Array(json["line"]).join(", ")}, #{json["postalCode"]} #{json["city"]}")
29
- end
30
-
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- module Lifen
2
- module Communication
3
- class Patient < Lifen::Base
4
-
5
- attribute :first_name, String
6
- attribute :last_name, String
7
- attribute :birthdate, Date
8
-
9
- def fhir_payload
10
- {
11
- id: "patient",
12
- resourceType: "Patient",
13
- name: [
14
- {
15
- family: [
16
- last_name
17
- ],
18
- given: [
19
- first_name
20
- ]
21
- }
22
- ],
23
- birthDate: birthdate.to_s
24
- }
25
- end
26
-
27
- end
28
- end
29
- end
@@ -1,61 +0,0 @@
1
- module Lifen
2
- module Communication
3
- class Request < Lifen::Base
4
-
5
- attribute :uuid, String
6
-
7
- attribute :sender, Lifen::User
8
- attribute :recipient, Lifen::User
9
-
10
- attribute :channel, Lifen::Communication::Channel
11
- attribute :patient, Lifen::Communication::Patient
12
- attribute :attachment, Lifen::Communication::Attachment
13
-
14
- def send
15
- json = application_client.post("fhir/CommunicationRequest", fhir_payload)
16
-
17
- self.uuid = json["id"]
18
-
19
- self
20
- end
21
-
22
- private
23
-
24
- def fhir_payload
25
- payload = {
26
- resourceType: "CommunicationRequest",
27
- sender: [ sender.fhir_payload ],
28
- recipient: [ recipient.fhir_payload ],
29
- contained: [ channel.fhir_payload(recipient) ],
30
- category: [ default_category],
31
- payload: [ attachment.fhir_payload ],
32
- }
33
-
34
- if patient
35
- payload[:contained] << patient.fhir_payload
36
- payload[:subject] = [
37
- {reference: "patient"}
38
- ]
39
- end
40
-
41
- payload
42
- end
43
-
44
- def default_category
45
- {
46
- coding: [
47
- {
48
- system: "http://honestica.com/fhir/communication/category",
49
- code: "MEDICAL_REPORT"
50
- }
51
- ]
52
- }
53
- end
54
-
55
- def application_client
56
- @application_client ||= AppAuthenticatedClient.new
57
- end
58
-
59
- end
60
- end
61
- end
@@ -1,75 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://develop.lifen.fr/fhir/CommunicationRequest
6
- body:
7
- encoding: UTF-8
8
- string: '{"resourceType":"CommunicationRequest","sender":[{"reference":"valid_sender_uuid"}],"recipient":[{"reference":"valid_recipient_uuid"}],"contained":[{"id":"valid_recipient_uuid","resourceType":"Practitioner","address":[{"id":"valid_channel_uuid"}]},{"id":"patient","resourceType":"Patient","name":[{"family":["Dupond"],"given":["Jean"]}],"birthDate":"2000-01-01"}],"category":[{"coding":[{"system":"http://honestica.com/fhir/communication/category","code":"MEDICAL_REPORT"}]}],"payload":[{"contentAttachment":{"data":"binary_data","title":"Master
9
- Plan","contentType":"{application/pdf}"}}],"subject":[{"reference":"patient"}]}'
10
- headers:
11
- User-Agent:
12
- - Faraday v0.11.0
13
- Authorization:
14
- - Bearer valid_application_access_token
15
- Content-Type:
16
- - application/json
17
- Accept:
18
- - application/json
19
- Accept-Encoding:
20
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
21
- response:
22
- status:
23
- code: 500
24
- message: Created
25
- headers:
26
- Server:
27
- - Apache-Coyote/1.1
28
- X-B3-Sampled:
29
- - '1'
30
- X-B3-Spanid:
31
- - 4033e9bebe0988e4
32
- X-B3-Traceid:
33
- - 4033e9bebe0988e4
34
- X-Content-Type-Options:
35
- - nosniff
36
- X-Xss-Protection:
37
- - 1; mode=block
38
- Cache-Control:
39
- - no-cache, no-store, max-age=0, must-revalidate
40
- Pragma:
41
- - no-cache
42
- Expires:
43
- - '0'
44
- X-Powered-By:
45
- - HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
46
- Content-Location:
47
- - http://develop.lifen.fr/fhir/OperationOutcome/a2f959a5-9211-48ee-8350-22bc02fee2b8
48
- Location:
49
- - http://develop.lifen.fr/fhir/OperationOutcome/a2f959a5-9211-48ee-8350-22bc02fee2b8
50
- Content-Type:
51
- - application/json+fhir;charset=UTF-8
52
- Transfer-Encoding:
53
- - chunked
54
- Date:
55
- - Tue, 07 Mar 2017 15:37:55 GMT
56
- Connection:
57
- - close
58
- Access-Control-Allow-Credentials:
59
- - 'true'
60
- body:
61
- encoding: UTF-8
62
- string: |-
63
- {
64
- "resourceType": "OperationOutcome",
65
- "id": "a2f959a5-9211-48ee-8350-22bc02fee2b8",
66
- "issue": [
67
- {
68
- "severity": "information",
69
- "diagnostics": "CommunicationRequest accepted"
70
- }
71
- ]
72
- }
73
- http_version:
74
- recorded_at: Tue, 07 Mar 2017 15:37:56 GMT
75
- recorded_with: VCR 3.0.3
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lifen::Communication::Request do
4
-
5
- let(:channel) { Lifen::Communication::Channel.new(uuid: "valid_channel_uuid", type: "address") } #valid_channel_uuid
6
-
7
- let(:sender) { Lifen::User.new(uuid: "valid_sender_uuid") } #valid_sender_uuid
8
- let(:recipient) { Lifen::User.new(uuid: "valid_recipient_uuid") } #valid_recipient_uuid
9
-
10
- let(:attachment) { Lifen::Communication::Attachment.new(title: "Master Plan", path: File.dirname(__FILE__) + "/support/master_plan.pdf", content_type: "application/pdf") }
11
-
12
- let(:patient) { Lifen::Communication::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1)) }
13
-
14
-
15
- describe ':send' do
16
-
17
- let(:request) { Lifen::Communication::Request.new(sender: sender, recipient: recipient, channel: channel, attachment: attachment, patient: patient) }
18
-
19
- it 'works' do
20
- VCR.use_cassette "request/send/valid_attributes" do
21
- request.send
22
- end
23
-
24
- expect(request.uuid).to_not be_nil
25
- end
26
-
27
- context 'invalid channel' do
28
-
29
- let(:channel) { Lifen::Communication::Channel.new(uuid: nil) }
30
-
31
- it 'raises an error' do
32
- expect{
33
- request.send
34
- }.to raise_error Lifen::Error, "Invalid channel: an UUID is required"
35
- end
36
-
37
- end
38
-
39
- end
40
-
41
- end