lifen_fhir 0.6.1 → 0.7.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: df513cd4eef4755920f805822b105e063326a30d
4
- data.tar.gz: a2492f576246c17d4ca92e4fa003cdb4d0443489
3
+ metadata.gz: 98ee8f12e62bce3ece87302a7f59beffac2cace2
4
+ data.tar.gz: a1c556adb2ee2d7812735e3b698e3502f0f27821
5
5
  SHA512:
6
- metadata.gz: 063e46e4be2297409ab7bb49594a6c163aa0b7db1734a193dea0287e28127a46b857e68fe3e6185c8899937f548154bec00737d4b5b4abc265cdd987e6f57e15
7
- data.tar.gz: 0b498dfb09d709a14c5dbf12b2c2c930201edd263808c31d574adc784e99f53341ecc3800fb3d6c60fc55ee57cbc109d2482ca6b70113d8c5712bbee3c3ae26c
6
+ metadata.gz: 8568d27fa40bceece25326db5ac747480b77eb1f08f82af6b637286d33ea015e521a6bb548f21c45e2ba9c12660f75c130073b903f64543d8db246edf18359c6
7
+ data.tar.gz: 2bcc675fa9e179696c75b0007a1914c7117337fb53391454e46af7e98c13ee580b33c8c4d455a90748745528625cf11f36c00c4f66358ab549382f8a0593d72e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.7.0
2
+ -----
3
+
4
+ - Add Communication object and allow to find by uuid
5
+ - Allow to find all communications based on a CommunicationRequest
6
+
1
7
  0.6.1
2
8
  -----
3
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen_fhir (0.6.1)
4
+ lifen_fhir (0.7.0)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
data/README.md CHANGED
@@ -96,8 +96,19 @@ communication_request = LifenFhir::CommunicationRequest.new(sender: sender, reci
96
96
  communication_request_request.send
97
97
 
98
98
  ```
99
+ #### Managing Communications
99
100
 
100
- ### Custom Channels management
101
+ ```ruby
102
+
103
+ #To load communications based on a communication_request
104
+ communication_request = LifenFhir::CommunicationRequest.new(uuid:"uuid")
105
+
106
+ communications = communication_request.communications
107
+
108
+ #To find communication by uuid
109
+ communication = LifenFhir::Communication.find_by_uuid("communication_uuid")
110
+ ```
111
+ #### Custom Channels management
101
112
 
102
113
  ```ruby
103
114
  recipient = LifenFhir::Practitioner.new(uuid: "valid-user-uuid")
@@ -6,7 +6,7 @@ module LifenFhir
6
6
  attribute :code, String, default: "MEDICAL_REPORT"
7
7
 
8
8
  def fhir_payload
9
- raise LifenFhir::Error, "Invalid category: code must be in the authorized values" if !valid?
9
+ raise Error.new(message: "Invalid category: code must be in the authorized values") if !valid?
10
10
 
11
11
  {
12
12
  coding: [
@@ -29,4 +29,4 @@ module LifenFhir
29
29
  end
30
30
 
31
31
  end
32
- end
32
+ end
@@ -7,7 +7,7 @@ module LifenFhir
7
7
  attribute :telecom, LifenFhir::Telecom
8
8
 
9
9
  def fhir_payload(user)
10
- raise LifenFhir::Error, "Invalid channel: an UUID is required" if !valid?
10
+ raise Error.new(message: "Invalid channel: an UUID is required") if !valid?
11
11
 
12
12
  {
13
13
  id: user.uuid,
@@ -36,4 +36,4 @@ module LifenFhir
36
36
  end
37
37
 
38
38
  end
39
- end
39
+ end
@@ -0,0 +1,83 @@
1
+ module LifenFhir
2
+ class Communication < Element
3
+
4
+ attribute :sender, Practitioner
5
+ attribute :recipient, Element
6
+ attribute :medium, Medium
7
+ attribute :binary, Binary
8
+
9
+ attribute :sent_at, DateTime
10
+ attribute :received_at, DateTime
11
+
12
+ attribute :status, String
13
+
14
+ STATUS = ["preparation", "in-progess", "suspended", "aborted", "completed" , "entered-in-error"]
15
+
16
+ def self.find_by_uuid(uuid)
17
+ json = application_client.get("fhir/Communication/#{uuid}")
18
+
19
+ communication = new
20
+ communication.attributes_from_json(json)
21
+
22
+ communication
23
+ end
24
+
25
+ def attributes_from_json(json)
26
+ self.uuid = json["id"]
27
+
28
+ self.status = json.fetch("status")
29
+
30
+ self.sent_at = json.fetch("sent") { "unknown" }
31
+
32
+ self.received_at = json["received"]
33
+
34
+ self.binary = Binary.new.attributes_from_json(Array(json["payload"]).first)
35
+
36
+ self.sender = Practitioner.new.attributes_from_json(json["sender"])
37
+
38
+ self.recipient = patient_or_practitioner(json["recipient"])
39
+
40
+ self.medium = Medium.new.attributes_from_json(extract_json_for_medium(json["medium"]))
41
+
42
+ raise Error.new(message: "Invalid Communication: status must be in the authorized values") if !valid?
43
+
44
+ self
45
+ end
46
+
47
+ def method_missing(method, *arguments, &block)
48
+ attribute_name = method.to_s.gsub!('is_', '')
49
+ if STATUS.include? attribute_name
50
+ self.status == attribute_name
51
+ else
52
+ super
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def patient_or_practitioner(recipient_reference)
59
+ m = Array(recipient_reference).first["reference"].match(/(.*)\/(.*)/)
60
+
61
+ case m[1]
62
+ when "Patient"
63
+ Patient.new(uuid: m[2])
64
+ when "Practitioner"
65
+ Practitioner.new(uuid: m[2])
66
+ end
67
+
68
+ end
69
+
70
+ def extract_json_for_medium(json)
71
+ json_coding = Array(json).first
72
+ json_medium = Array(json_coding["coding"]).first
73
+
74
+ json_medium
75
+ end
76
+
77
+ def valid?
78
+ STATUS.include? self.status
79
+ end
80
+
81
+
82
+ end
83
+ end
@@ -2,19 +2,24 @@ module LifenFhir
2
2
  class CommunicationRequest < Element
3
3
 
4
4
  attribute :number_communications, Integer
5
+ attribute :json_payload, Hash
5
6
 
6
- attribute :sender, LifenFhir::Sender
7
- attribute :recipients, [LifenFhir::Recipient]
7
+ attribute :sender, Sender
8
+ attribute :recipients, [Recipient]
8
9
 
9
- attribute :category, LifenFhir::Category, default: LifenFhir::Category.new
10
- attribute :medium, [LifenFhir::Medium]
11
- attribute :patient, LifenFhir::Patient
12
- attribute :attachment, LifenFhir::Attachment
13
- attribute :binary, LifenFhir::Binary
14
- attribute :content_string, LifenFhir::ContentString
10
+ attribute :category, Category, default: Category.new
11
+ attribute :medium, [Medium]
12
+ attribute :patient, Patient
13
+ attribute :attachment, Attachment
14
+ attribute :binary, Binary
15
+ attribute :content_string, ContentString
16
+
17
+ attribute :communications, [Communication], default: []
15
18
 
16
19
  attribute :status, String
17
20
 
21
+ PAYLOAD_ATTRIBUTES = ["sender", "recipient", "payload", "category"]
22
+
18
23
  def send
19
24
  json = application_client.post("fhir/CommunicationRequest", fhir_payload)
20
25
 
@@ -33,28 +38,49 @@ module LifenFhir
33
38
  communication_request
34
39
  end
35
40
 
41
+ def communications
42
+ if !@communications_loaded
43
+ load_communications
44
+ @communications_loaded = true
45
+ end
46
+
47
+ @communications
48
+ end
49
+
36
50
  def attributes_from_json(json)
51
+ self.json_payload = json
52
+
37
53
  self.uuid = json["id"]
38
54
 
39
55
  self.status = json.fetch("status") { "unknown" }
40
56
 
41
- if has_payload?(json)
57
+ if has_payload
42
58
  self.binary = Binary.new.attributes_from_json(Array(json["payload"]).first)
43
59
  end
44
60
 
45
- if has_category?(json)
61
+ if has_category
46
62
  self.category = Category.new.attributes_from_json(Array(json["category"]).first)
47
63
  end
48
64
 
49
- if has_sender?(json)
65
+ if has_sender
50
66
  self.sender = Practitioner.new.attributes_from_json(json["sender"])
51
67
  end
52
68
 
53
- if has_recipient?(json)
69
+ if has_recipient
54
70
  self.recipients = Array(json["recipient"]).map do |recipient_json|
55
71
  Practitioner.new.attributes_from_json(recipient_json)
56
72
  end
57
73
  end
74
+
75
+ end
76
+
77
+ def method_missing(method, *arguments, &block)
78
+ attribute_name = method.to_s.gsub!('has_', '')
79
+ if PAYLOAD_ATTRIBUTES.include? attribute_name
80
+ json_payload.key?(attribute_name)
81
+ else
82
+ super
83
+ end
58
84
  end
59
85
 
60
86
  private
@@ -93,20 +119,20 @@ module LifenFhir
93
119
  end
94
120
  end
95
121
 
96
- def has_category?(json)
97
- json.key?("category")
98
- end
122
+ def load_communications
123
+ json = application_client.get("/fhir/Communication?based-on=#{uuid}")
99
124
 
100
- def has_sender?(json)
101
- json.key?("sender")
102
- end
125
+ @communications = Array(json["entry"]).map do |entry_json|
126
+ Communication.new.attributes_from_json(entry_json["resource"])
127
+ end
103
128
 
104
- def has_recipient?(json)
105
- json.key?("recipient")
129
+ @communications_loaded = true
106
130
  end
107
131
 
108
- def has_payload?(json)
109
- json.key?("payload")
132
+ def communications_loaded
133
+ @communications_loaded ||= false
110
134
  end
135
+
136
+
111
137
  end
112
138
  end
@@ -17,7 +17,7 @@ module LifenFhir
17
17
 
18
18
  def site=(url)
19
19
  if !/(.*)\/$/.match(url)
20
- raise LifenFhir::Error, "Invalid 'site' provided in configuration: '#{url}', a trailing slash is missing"
20
+ raise Error.new(message: "Invalid 'site' provided in configuration: '#{url}', a trailing slash is missing")
21
21
  end
22
22
 
23
23
  @site = url
@@ -31,4 +31,4 @@ module LifenFhir
31
31
  def self.configure
32
32
  yield(configuration) if block_given?
33
33
  end
34
- end
34
+ end
@@ -1,6 +1,11 @@
1
1
  module LifenFhir
2
2
  class Medium < Element
3
3
 
4
+ attribute :code, String
5
+ attribute :display, String
6
+ attribute :value, String
7
+
8
+
4
9
  def fhir_payload
5
10
  {
6
11
  coding:[{
@@ -9,5 +14,14 @@ module LifenFhir
9
14
  }
10
15
  end
11
16
 
17
+ def attributes_from_json(json)
18
+
19
+ self.display = json["display"]
20
+ self.code = json["code"]
21
+ self.value = json["value"]
22
+
23
+ self
24
+ end
25
+
12
26
  end
13
- end
27
+ end
@@ -1,7 +1,7 @@
1
1
  module LifenFhir
2
2
  class Practitioner < Element
3
3
 
4
- attribute :channels, [LifenFhir::Channel]
4
+ attribute :channels, [Channel]
5
5
 
6
6
  attribute :last_name, String
7
7
  attribute :first_name, String
@@ -23,11 +23,11 @@ module LifenFhir
23
23
  user = new(user_json)
24
24
 
25
25
  Array(user_json["telecom"]).each do |telecom_json|
26
- user.channels << LifenFhir::Channel.from_json(telecom_json, "telecom")
26
+ user.channels << Channel.from_json(telecom_json, "telecom")
27
27
  end
28
28
 
29
29
  Array(user_json["address"]).each do |address_json|
30
- user.channels << LifenFhir::Channel.from_json(address_json, "address")
30
+ user.channels << Channel.from_json(address_json, "address")
31
31
  end
32
32
 
33
33
  user
@@ -1,3 +1,3 @@
1
1
  module LifenFhir
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/lifen_fhir.rb CHANGED
@@ -37,6 +37,7 @@ module LifenFhir
37
37
  require 'lifen_fhir/binary'
38
38
  require 'lifen_fhir/patient'
39
39
  require 'lifen_fhir/content_string'
40
+ require 'lifen_fhir/communication'
40
41
  require 'lifen_fhir/communication_request'
41
42
 
42
43
  Virtus.finalize
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/non_valid_communication_uuid
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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: OK
22
+ headers:
23
+ Server:
24
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - e8588d4e752a3c79
27
+ X-B3-Spanid:
28
+ - e8588d4e752a3c79
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Location:
42
+ - http://rc.lifen.fr/fhir/Communication/11e74a9a-c769-ada3-81a2-0242ac110004
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Tue, 06 Jun 2017 09:51:56 GMT
49
+ Access-Control-Allow-Credentials:
50
+ - 'true'
51
+ body:
52
+ encoding: UTF-8
53
+ string: |-
54
+ {
55
+ "resourceType": "Communication",
56
+ "id": "11e74a9a-c769-ada3-81a2-0242ac110004",
57
+ "status": "non_valid_status",
58
+ "medium": [
59
+ {
60
+ "coding": [
61
+ {
62
+ "system": "http://honestica.com/fhir/channel",
63
+ "code": "PAPER",
64
+ "display": "DR Xavier Apicrypt,33 rue des Buchers,31000 Toulouse"
65
+ }
66
+ ]
67
+ }
68
+ ],
69
+ "recipient": [
70
+ {
71
+ "reference": "Practitioner/11e5b841-4ff8-2dbb-9643-eabb809fa654"
72
+ }
73
+ ],
74
+ "sent": "2017-06-06T09:50:51+00:00",
75
+ "received": "2017-06-06T09:30:28+00:00",
76
+ "sender": {
77
+ "reference": "Practitioner/11e5b841-4ff1-2dbb-9643-eabb809fa654"
78
+ },
79
+ "payload": [
80
+ {
81
+ "contentReference": {
82
+ "reference": "Binary/11e7317b-d85e-5aa9-bdf4-0242ac110004"
83
+ }
84
+ }
85
+ ]
86
+ }
87
+ http_version:
88
+ recorded_at: Tue, 06 Jun 2017 09:51:17 GMT
89
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,64 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/non_valid_communication_uuid
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - d25962660c460cd1
27
+ X-B3-Spanid:
28
+ - d25962660c460cd1
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Content-Type:
42
+ - application/json+fhir;charset=UTF-8
43
+ Transfer-Encoding:
44
+ - chunked
45
+ Date:
46
+ - Tue, 06 Jun 2017 11:51:14 GMT
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ body:
50
+ encoding: UTF-8
51
+ string: |-
52
+ {
53
+ "resourceType": "OperationOutcome",
54
+ "issue": [
55
+ {
56
+ "severity": "error",
57
+ "code": "not-found",
58
+ "diagnostics": "Unknown Resource id=non_valid_communication_uuid"
59
+ }
60
+ ]
61
+ }
62
+ http_version:
63
+ recorded_at: Tue, 06 Jun 2017 11:50:35 GMT
64
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,90 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/11e75015-3d29-bcc5-998e-0242ac110005
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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: OK
22
+ headers:
23
+ Server:
24
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - 3a2e4006acae5706
27
+ X-B3-Spanid:
28
+ - 3a2e4006acae5706
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Location:
42
+ - http://rc.lifen.fr/fhir/Communication/11e75015-3d29-bcc5-998e-0242ac110005
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Tue, 13 Jun 2017 09:55:36 GMT
49
+ Connection:
50
+ - close
51
+ Access-Control-Allow-Credentials:
52
+ - 'true'
53
+ body:
54
+ encoding: UTF-8
55
+ string: |-
56
+ {
57
+ "resourceType": "Communication",
58
+ "id": "11e75015-3d29-bcc5-998e-0242ac110005",
59
+ "status": "preparation",
60
+ "medium": [
61
+ {
62
+ "coding": [
63
+ {
64
+ "system": "http://honestica.com/fhir/channel",
65
+ "code": "PAPER",
66
+ "display": "39 rue d'Aboukir,75002 PARIS"
67
+ }
68
+ ]
69
+ }
70
+ ],
71
+ "recipient": [
72
+ {
73
+ "reference": "Patient/7d8d1805-eb43-4203-ab20-94a042b9d932"
74
+ }
75
+ ],
76
+ "received": "2017-06-13T08:49:40+00:00",
77
+ "sender": {
78
+ "reference": "Practitioner/11e5b841-4faa-2dbb-9643-eabb809fa654"
79
+ },
80
+ "payload": [
81
+ {
82
+ "contentReference": {
83
+ "reference": "Binary/11e74f87-9de7-9b32-9823-0242ac110005"
84
+ }
85
+ }
86
+ ]
87
+ }
88
+ http_version:
89
+ recorded_at: Tue, 13 Jun 2017 09:55:19 GMT
90
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication/11e74a9a-c769-ada3-81a2-0242ac110004
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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: OK
22
+ headers:
23
+ Server:
24
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - e8588d4e752a3c79
27
+ X-B3-Spanid:
28
+ - e8588d4e752a3c79
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Location:
42
+ - http://rc.lifen.fr/fhir/Communication/11e74a9a-c769-ada3-81a2-0242ac110004
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Tue, 06 Jun 2017 09:51:56 GMT
49
+ Access-Control-Allow-Credentials:
50
+ - 'true'
51
+ body:
52
+ encoding: UTF-8
53
+ string: |-
54
+ {
55
+ "resourceType": "Communication",
56
+ "id": "11e74a9a-c769-ada3-81a2-0242ac110004",
57
+ "status": "preparation",
58
+ "medium": [
59
+ {
60
+ "coding": [
61
+ {
62
+ "system": "http://honestica.com/fhir/channel",
63
+ "code": "PAPER",
64
+ "display": "DR Xavier Apicrypt,33 rue des Buchers,31000 Toulouse"
65
+ }
66
+ ]
67
+ }
68
+ ],
69
+ "recipient": [
70
+ {
71
+ "reference": "Practitioner/11e5b841-4ff8-2dbb-9643-eabb809fa654"
72
+ }
73
+ ],
74
+ "sent": "2017-06-06T09:50:51+00:00",
75
+ "received": "2017-06-06T09:30:28+00:00",
76
+ "sender": {
77
+ "reference": "Practitioner/11e5b841-4ff1-2dbb-9643-eabb809fa654"
78
+ },
79
+ "payload": [
80
+ {
81
+ "contentReference": {
82
+ "reference": "Binary/11e7317b-d85e-5aa9-bdf4-0242ac110004"
83
+ }
84
+ }
85
+ ]
86
+ }
87
+ http_version:
88
+ recorded_at: Tue, 06 Jun 2017 09:51:17 GMT
89
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,144 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication?based-on=966d7c0b-ebf7-42f6-8be7-7b97321c6398
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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: OK
22
+ headers:
23
+ Server:
24
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - 0f6e9cdda06c3059
27
+ X-B3-Spanid:
28
+ - 0f6e9cdda06c3059
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Last-Modified:
42
+ - Wed, 07 Jun 2017 14:26:47 GMT
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Wed, 07 Jun 2017 14:26:47 GMT
49
+ Access-Control-Allow-Credentials:
50
+ - 'true'
51
+ body:
52
+ encoding: UTF-8
53
+ string: |-
54
+ {
55
+ "resourceType": "Bundle",
56
+ "id": "1bb86bc5-2cb9-4a38-bcac-92617e817291",
57
+ "meta": {
58
+ "lastUpdated": "2017-06-07T14:26:47.356+00:00"
59
+ },
60
+ "type": "searchset",
61
+ "total": 2,
62
+ "link": [
63
+ {
64
+ "relation": "self",
65
+ "url": "http://rc.lifen.fr/fhir/Communication?based-on=966d7c0b-ebf7-42f6-8be7-7b97321c6398"
66
+ }
67
+ ],
68
+ "entry": [
69
+ {
70
+ "fullUrl": "http://rc.lifen.fr/fhir/Communication/11e749e3-941e-7f89-8605-0242ac110004",
71
+ "resource": {
72
+ "resourceType": "Communication",
73
+ "id": "11e749e3-941e-7f89-8605-0242ac110004",
74
+ "status": "completed",
75
+ "medium": [
76
+ {
77
+ "coding": [
78
+ {
79
+ "system": "http://honestica.com/fhir/channel",
80
+ "code": "LIFEN"
81
+ }
82
+ ]
83
+ }
84
+ ],
85
+ "recipient": [
86
+ {
87
+ "reference": "Practitioner/11e5b841-4ff8-2dbb-9643-eabb809fa654"
88
+ }
89
+ ],
90
+ "sent": "2017-06-05T11:39:05+00:00",
91
+ "received": "2017-06-05T11:39:04+00:00",
92
+ "sender": {
93
+ "reference": "Practitioner/11e5b841-4ff1-2dbb-9643-eabb809fa654"
94
+ },
95
+ "payload": [
96
+ {
97
+ "contentReference": {
98
+ "reference": "Binary/11e7317b-d85e-5aa9-bdf4-0242ac110004"
99
+ }
100
+ }
101
+ ]
102
+ }
103
+ },
104
+ {
105
+ "fullUrl": "http://rc.lifen.fr/fhir/Communication/11e749e3-942b-77e9-8605-0242ac110004",
106
+ "resource": {
107
+ "resourceType": "Communication",
108
+ "id": "11e749e3-942b-77e9-8605-0242ac110004",
109
+ "status": "completed",
110
+ "medium": [
111
+ {
112
+ "coding": [
113
+ {
114
+ "system": "http://honestica.com/fhir/channel",
115
+ "code": "APICRYPT",
116
+ "display": "emilie@honestica.com"
117
+ }
118
+ ]
119
+ }
120
+ ],
121
+ "recipient": [
122
+ {
123
+ "reference": "Practitioner/11e5b841-4ff8-2dbb-9643-eabb809fa654"
124
+ }
125
+ ],
126
+ "sent": "2017-06-05T11:39:05+00:00",
127
+ "received": "2017-06-05T11:39:05+00:00",
128
+ "sender": {
129
+ "reference": "Practitioner/11e5b841-4ff1-2dbb-9643-eabb809fa654"
130
+ },
131
+ "payload": [
132
+ {
133
+ "contentReference": {
134
+ "reference": "Binary/11e7317b-d85e-5aa9-bdf4-0242ac110004"
135
+ }
136
+ }
137
+ ]
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ http_version:
143
+ recorded_at: Wed, 07 Jun 2017 14:26:47 GMT
144
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,110 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication?based-on=07937186-d95c-4947-a9b3-b0208ef1d4c4
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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: OK
22
+ headers:
23
+ Server:
24
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - c9d9f123b93085a7
27
+ X-B3-Spanid:
28
+ - c9d9f123b93085a7
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Last-Modified:
42
+ - Tue, 13 Jun 2017 10:14:44 GMT
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Tue, 13 Jun 2017 10:14:44 GMT
49
+ Connection:
50
+ - close
51
+ Access-Control-Allow-Credentials:
52
+ - 'true'
53
+ body:
54
+ encoding: UTF-8
55
+ string: |-
56
+ {
57
+ "resourceType": "Bundle",
58
+ "id": "257386e9-33a4-45a7-bb70-dfcc4a94ae9a",
59
+ "meta": {
60
+ "lastUpdated": "2017-06-13T10:14:44.964+00:00"
61
+ },
62
+ "type": "searchset",
63
+ "total": 1,
64
+ "link": [
65
+ {
66
+ "relation": "self",
67
+ "url": "http://rc.lifen.fr/fhir/Communication?based-on=07937186-d95c-4947-a9b3-b0208ef1d4c4"
68
+ }
69
+ ],
70
+ "entry": [
71
+ {
72
+ "fullUrl": "http://rc.lifen.fr/fhir/Communication/11e75015-3d29-bcc5-998e-0242ac110005",
73
+ "resource": {
74
+ "resourceType": "Communication",
75
+ "id": "11e75015-3d29-bcc5-998e-0242ac110005",
76
+ "status": "preparation",
77
+ "medium": [
78
+ {
79
+ "coding": [
80
+ {
81
+ "system": "http://honestica.com/fhir/channel",
82
+ "code": "PAPER",
83
+ "display": "39 rue d'Aboukir,75002 PARIS"
84
+ }
85
+ ]
86
+ }
87
+ ],
88
+ "recipient": [
89
+ {
90
+ "reference": "Patient/7d8d1805-eb43-4203-ab20-94a042b9d932"
91
+ }
92
+ ],
93
+ "received": "2017-06-13T08:49:40+00:00",
94
+ "sender": {
95
+ "reference": "Practitioner/11e5b841-4faa-2dbb-9643-eabb809fa654"
96
+ },
97
+ "payload": [
98
+ {
99
+ "contentReference": {
100
+ "reference": "Binary/11e74f87-9de7-9b32-9823-0242ac110005"
101
+ }
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ ]
107
+ }
108
+ http_version:
109
+ recorded_at: Tue, 13 Jun 2017 10:14:28 GMT
110
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,64 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Communication?based-on=non_valid_request_uuid
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.1
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/json
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
+ - Apache-Coyote/1.1
25
+ X-B3-Traceid:
26
+ - 21de781f04efc7b3
27
+ X-B3-Spanid:
28
+ - 21de781f04efc7b3
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Cache-Control:
34
+ - no-cache, no-store, max-age=0, must-revalidate
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - '0'
39
+ X-Powered-By:
40
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
41
+ Content-Type:
42
+ - application/json+fhir;charset=UTF-8
43
+ Transfer-Encoding:
44
+ - chunked
45
+ Date:
46
+ - Wed, 07 Jun 2017 14:26:48 GMT
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ body:
50
+ encoding: UTF-8
51
+ string: |-
52
+ {
53
+ "resourceType": "OperationOutcome",
54
+ "issue": [
55
+ {
56
+ "severity": "error",
57
+ "code": "not-found",
58
+ "diagnostics": "Failed to find communication request or communication related."
59
+ }
60
+ ]
61
+ }
62
+ http_version:
63
+ recorded_at: Wed, 07 Jun 2017 14:26:48 GMT
64
+ recorded_with: VCR 3.0.3
@@ -196,10 +196,6 @@ describe LifenFhir::CommunicationRequest do
196
196
  end
197
197
  end
198
198
 
199
- context 'with a patient' do
200
- pending "works"
201
- end
202
-
203
199
  context 'with invalid uuid' do
204
200
 
205
201
  it 'fails nicely' do
@@ -214,4 +210,70 @@ describe LifenFhir::CommunicationRequest do
214
210
 
215
211
  end
216
212
 
213
+ describe ':load_communications' do
214
+
215
+ context 'load_communications with valid_uuid' do
216
+
217
+ let(:communication_request) { LifenFhir::CommunicationRequest.new(uuid:"966d7c0b-ebf7-42f6-8be7-7b97321c6398") }
218
+
219
+ it 'works' do
220
+
221
+ VCR.use_cassette "communication_request/load_communications/commmunications_based_on" do
222
+ communication_request.communications
223
+ end
224
+
225
+ expect(communication_request.communications.count).to eq(2)
226
+
227
+ expect(communication_request.communications.first.recipient.uuid).to eq("11e5b841-4ff8-2dbb-9643-eabb809fa654")
228
+ expect(communication_request.communications.first.sender.uuid).to eq("11e5b841-4ff1-2dbb-9643-eabb809fa654")
229
+ expect(communication_request.communications.first.sender.uuid).to eq("11e5b841-4ff1-2dbb-9643-eabb809fa654")
230
+
231
+ expect(communication_request.communications.first.medium.code).to eq("LIFEN")
232
+ expect(communication_request.communications[1].medium.code).to eq("APICRYPT")
233
+ expect(communication_request.communications[1].medium.display).to eq("emilie@honestica.com")
234
+
235
+ expect(communication_request.communications.first.is_completed).to be_truthy
236
+ expect(communication_request.communications[1].is_completed).to be_truthy
237
+
238
+ expect(communication_request.communications.first.sent_at).to eq(DateTime.new(2017, 06, 05, 11, 39, 5))
239
+ expect(communication_request.communications.first.received_at).to eq(DateTime.new(2017, 06, 05, 11, 39, 4))
240
+
241
+ expect(communication_request.communications[1].sent_at).to eq(DateTime.new(2017, 06, 05, 11, 39, 5))
242
+ expect(communication_request.communications[1].received_at).to eq(DateTime.new(2017, 06, 05, 11, 39, 5))
243
+
244
+ end
245
+ end
246
+
247
+ context 'load_communications with non valid communication_request uuid' do
248
+
249
+ let(:communication_request) { LifenFhir::CommunicationRequest.new(uuid:"non_valid_request_uuid") }
250
+
251
+ it 'fails nicely' do
252
+
253
+ expect{ VCR.use_cassette "communication_request/load_communications/non_valid_request_uuid" do
254
+ communication_request.communications
255
+ end
256
+ }.to raise_error LifenFhir::Error
257
+
258
+
259
+ end
260
+ end
261
+
262
+ context 'with a patient as recipient' do
263
+
264
+ let(:communication_request) { LifenFhir::CommunicationRequest.new(uuid:"07937186-d95c-4947-a9b3-b0208ef1d4c4") }
265
+
266
+ it 'works' do
267
+
268
+ VCR.use_cassette "communication_request/load_communications/commmunications_based_on_with_patient" do
269
+ communication_request.communications
270
+ end
271
+
272
+ expect(communication_request.communications.count).to eq(1)
273
+ expect(communication_request.communications.first.recipient.class.name).to eq("LifenFhir::Patient")
274
+ expect(communication_request.communications.first.medium.display).to eq("39 rue d'Aboukir,75002 PARIS")
275
+ end
276
+
277
+ end
278
+ end
217
279
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe LifenFhir::Communication do
4
+
5
+ describe ':find_by_uuid' do
6
+
7
+ context 'valid communication_uuid' do
8
+
9
+ it 'works' do
10
+ VCR.use_cassette "communication/find_by_uuid/valid_uuid" do
11
+ @communication = LifenFhir::Communication.find_by_uuid("11e74a9a-c769-ada3-81a2-0242ac110004")
12
+ end
13
+ expect(@communication.uuid).to eq("11e74a9a-c769-ada3-81a2-0242ac110004")
14
+
15
+
16
+ expect(@communication.sender.uuid).to eq("11e5b841-4ff1-2dbb-9643-eabb809fa654")
17
+
18
+ expect(@communication.recipient.uuid).to eq("11e5b841-4ff8-2dbb-9643-eabb809fa654")
19
+ expect(@communication.recipient.class.name).to eq("LifenFhir::Practitioner")
20
+
21
+ expect(@communication.medium.display).to eq("DR Xavier Apicrypt,33 rue des Buchers,31000 Toulouse")
22
+ expect(@communication.medium.code).to eq("PAPER")
23
+
24
+ expect(@communication.status).to eq("preparation")
25
+
26
+ end
27
+ end
28
+
29
+ context 'non valid communication_uuid' do
30
+
31
+ it 'fails nicely' do
32
+ expect{ VCR.use_cassette "communication/find_by_uuid/non_valid_uuid" do
33
+ @communication = LifenFhir::Communication.find_by_uuid("non_valid_communication_uuid")
34
+ end
35
+ }.to raise_error LifenFhir::Error
36
+ end
37
+ end
38
+
39
+ context 'non valid status' do
40
+
41
+ it 'fails nicely' do
42
+ expect{ VCR.use_cassette "communication/find_by_uuid/non_valid_status" do
43
+ @communication = LifenFhir::Communication.find_by_uuid("non_valid_communication_uuid")
44
+ end
45
+ }.to raise_error LifenFhir::Error
46
+ end
47
+
48
+ end
49
+
50
+ context 'recipient is a patient' do
51
+
52
+ it 'works' do
53
+ VCR.use_cassette "communication/find_by_uuid/recipient_is_patient" do
54
+ @communication = LifenFhir::Communication.find_by_uuid("11e75015-3d29-bcc5-998e-0242ac110005")
55
+ end
56
+
57
+ expect(@communication.uuid).to eq("11e75015-3d29-bcc5-998e-0242ac110005")
58
+
59
+
60
+ expect(@communication.sender.uuid).to eq("11e5b841-4faa-2dbb-9643-eabb809fa654")
61
+
62
+ expect(@communication.recipient.uuid).to eq("7d8d1805-eb43-4203-ab20-94a042b9d932")
63
+ expect(@communication.recipient.class.name).to eq("LifenFhir::Patient")
64
+
65
+ expect(@communication.medium.display).to eq("39 rue d'Aboukir,75002 PARIS")
66
+ expect(@communication.medium.code).to eq("PAPER")
67
+
68
+ expect(@communication.status).to eq("preparation")
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+ end
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.6.1
4
+ version: 0.7.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-07 00:00:00.000000000 Z
12
+ date: 2017-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -205,6 +205,7 @@ files:
205
205
  - lib/lifen_fhir/category.rb
206
206
  - lib/lifen_fhir/channel.rb
207
207
  - lib/lifen_fhir/client.rb
208
+ - lib/lifen_fhir/communication.rb
208
209
  - lib/lifen_fhir/communication_request.rb
209
210
  - lib/lifen_fhir/configuration.rb
210
211
  - lib/lifen_fhir/content_string.rb
@@ -222,11 +223,18 @@ files:
222
223
  - spec/binary_spec.rb
223
224
  - spec/cassettes/binary/download/invalid.yml
224
225
  - spec/cassettes/binary/download/valid.yml
226
+ - spec/cassettes/communication/find_by_uuid/non_valid_status.yml
227
+ - spec/cassettes/communication/find_by_uuid/non_valid_uuid.yml
228
+ - spec/cassettes/communication/find_by_uuid/recipient_is_patient.yml
229
+ - spec/cassettes/communication/find_by_uuid/valid_uuid.yml
225
230
  - spec/cassettes/communication_request/find_by_uuid/invalid_uuid.yml
226
231
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_a_status.yml
227
232
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_no_status.yml
228
233
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_status_and_binary_only.yml
229
234
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_status_only.yml
235
+ - spec/cassettes/communication_request/load_communications/commmunications_based_on.yml
236
+ - spec/cassettes/communication_request/load_communications/commmunications_based_on_with_patient.yml
237
+ - spec/cassettes/communication_request/load_communications/non_valid_request_uuid.yml
230
238
  - spec/cassettes/communication_request/send/invalid_medium.yml
231
239
  - spec/cassettes/communication_request/send/patient/invalid_attributes_binary.yml
232
240
  - spec/cassettes/communication_request/send/patient/valid_attributes_binary.yml
@@ -253,6 +261,7 @@ files:
253
261
  - spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
254
262
  - spec/category_spec.rb
255
263
  - spec/communication_request_spec.rb
264
+ - spec/communication_spec.rb
256
265
  - spec/error_spec.rb
257
266
  - spec/logger_spec.rb
258
267
  - spec/patient_spec.rb
@@ -288,11 +297,18 @@ test_files:
288
297
  - spec/binary_spec.rb
289
298
  - spec/cassettes/binary/download/invalid.yml
290
299
  - spec/cassettes/binary/download/valid.yml
300
+ - spec/cassettes/communication/find_by_uuid/non_valid_status.yml
301
+ - spec/cassettes/communication/find_by_uuid/non_valid_uuid.yml
302
+ - spec/cassettes/communication/find_by_uuid/recipient_is_patient.yml
303
+ - spec/cassettes/communication/find_by_uuid/valid_uuid.yml
291
304
  - spec/cassettes/communication_request/find_by_uuid/invalid_uuid.yml
292
305
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_a_status.yml
293
306
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_no_status.yml
294
307
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_status_and_binary_only.yml
295
308
  - spec/cassettes/communication_request/find_by_uuid/valid_uuid_with_status_only.yml
309
+ - spec/cassettes/communication_request/load_communications/commmunications_based_on.yml
310
+ - spec/cassettes/communication_request/load_communications/commmunications_based_on_with_patient.yml
311
+ - spec/cassettes/communication_request/load_communications/non_valid_request_uuid.yml
296
312
  - spec/cassettes/communication_request/send/invalid_medium.yml
297
313
  - spec/cassettes/communication_request/send/patient/invalid_attributes_binary.yml
298
314
  - spec/cassettes/communication_request/send/patient/valid_attributes_binary.yml
@@ -319,6 +335,7 @@ test_files:
319
335
  - spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
320
336
  - spec/category_spec.rb
321
337
  - spec/communication_request_spec.rb
338
+ - spec/communication_spec.rb
322
339
  - spec/error_spec.rb
323
340
  - spec/logger_spec.rb
324
341
  - spec/patient_spec.rb