lifen_fhir 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1db22fe4077504ea3f23585828eb697f22763c39
4
- data.tar.gz: 5fcccdd90ef76bea15800c296280788d02c3f168
3
+ metadata.gz: 9f98c168e0842426a55c637ba522c9dab7676c55
4
+ data.tar.gz: ce0fdeb504d1a29c9772be8e9b7475fbf40731b2
5
5
  SHA512:
6
- metadata.gz: 392a47b43059e7eb3f844f7ab5244290697b815734db38403c895f2acba03d52f75bd45e52ae91732535be5d6a84e22da3e2e8b4cb362acbc5120a7c2f2ce2d0
7
- data.tar.gz: 6ca727e4b24cdbeda29c4b00ade9223700109dfc3e2904f7ff366ac460c0966e5ada293439a0956ef702dce97ad23df74febc81ffadef47d66781750685adf75
6
+ metadata.gz: 519aebce8e4b8f2241a2adf538334866ad5d5fd01a87a3aa1d76259de25c754ac46a7cdb6545ffbdbf2c5e711bdb474cffde012a404a75b5bacc401be9c1c80e
7
+ data.tar.gz: 63935aa6a344360bc8ea69eb3114e11731011fb6ed14f9d5ebf8020ce4e466af2b8b05876665fe90bd34713534341c450c0217844a180131dc9f01c3898ccdab
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.3.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.0
2
+ -----
3
+
4
+ - Added the Patient and the Address objects
5
+
1
6
  0.1.1
2
7
  -----
3
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen_fhir (0.1.1)
4
+ lifen_fhir (0.2.0)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
data/README.md CHANGED
@@ -94,6 +94,17 @@ channel = recipient.create_address(type: "address", lines: ["39 rue Aboukir"], c
94
94
  channel = recipient.create_telecom(type: "telecom", system: "fax", value: "+33102030405")
95
95
  ```
96
96
 
97
+ #### Managing Patients
98
+
99
+ ```ruby
100
+ # To create a new patient
101
+ address = LifenFhir::Address.new(lines: ["39 rue d'Aboukir"], city: "Paris", postal_code: "75002")
102
+ patient = LifenFhir::Patient.create(first_name: ["Jean", "Charles"], last_name: "Dupond", birth_date: Date.new(1974, 12, 25), address: address)
103
+
104
+ # To find a patient by id
105
+ patient = LifenFhir::Patient.find_by_uuid("c3f96278-3bfe-4933-96e7-171ebca7489f")
106
+ ```
107
+
97
108
  ## Deploying to Rubygems
98
109
 
99
110
  Once the new version is validated, the deployment follows those steps :
@@ -0,0 +1,29 @@
1
+ module LifenFhir
2
+ class Address < Base
3
+
4
+ attribute :uuid, String
5
+
6
+ attribute :lines, [String]
7
+ attribute :postal_code, String
8
+ attribute :city, String
9
+
10
+ def attributes_from_json(json)
11
+ self.lines = Array(json.fetch("line"))
12
+
13
+ self.postal_code = json.fetch("postalCode")
14
+
15
+ self.city = json.fetch("city")
16
+
17
+ self
18
+ end
19
+
20
+ def create_payload
21
+ {
22
+ "line": lines,
23
+ "city": city,
24
+ "postalCode": postal_code
25
+ }
26
+ end
27
+
28
+ end
29
+ end
@@ -1,9 +1,34 @@
1
1
  module LifenFhir
2
2
  class Patient < Base
3
3
 
4
- attribute :first_name, String
4
+ attribute :uuid, String
5
+
6
+ attribute :first_name, [String]
5
7
  attribute :last_name, String
6
- attribute :birthdate, Date
8
+ attribute :birth_date, Date
9
+
10
+ attribute :address, Address
11
+
12
+ def self.create(params)
13
+ new(params).save
14
+ end
15
+
16
+ def save
17
+ json = application_client.post("fhir/Patient", create_payload)
18
+
19
+ self.uuid = json["id"]
20
+
21
+ self
22
+ end
23
+
24
+ def self.find_by_uuid(uuid)
25
+ json = application_client.get("fhir/Patient/#{uuid}")
26
+
27
+ patient = new
28
+ patient.attributes_from_json(json)
29
+
30
+ patient
31
+ end
7
32
 
8
33
  def fhir_payload
9
34
  {
@@ -19,9 +44,54 @@ module LifenFhir
19
44
  ]
20
45
  }
21
46
  ],
22
- birthDate: birthdate.to_s
47
+ birthDate: birth_date.to_s
23
48
  }
24
49
  end
25
50
 
51
+ def attributes_from_json(json)
52
+ self.uuid = json["id"]
53
+
54
+ full_name = Array(json["name"]).first
55
+
56
+ self.first_name = Array(full_name["given"])
57
+ self.last_name = full_name["family"]
58
+
59
+ self.birth_date = json["birthDate"]
60
+
61
+ address_json = json["address"].first
62
+ self.address = Address.new.attributes_from_json(address_json)
63
+ end
64
+
65
+ private
66
+
67
+
68
+ def create_payload
69
+ filtered_params = {"resourceType" => "Patient"}
70
+
71
+ filtered_params["name"] = [{
72
+ "family": last_name,
73
+ "given": first_name
74
+ }]
75
+
76
+ if address
77
+ filtered_params["address"] = [
78
+ address.create_payload
79
+ ]
80
+ end
81
+
82
+ filtered_params["birthDate"] = birth_date.to_s
83
+
84
+ filtered_params
85
+ end
86
+
87
+ def application_client
88
+ @application_client ||= AppAuthenticatedClient.new
89
+ end
90
+
91
+
92
+ def self.application_client
93
+ @application_client ||= AppAuthenticatedClient.new
94
+ end
95
+
26
96
  end
27
- end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module LifenFhir
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/lifen_fhir.rb CHANGED
@@ -14,6 +14,7 @@ module LifenFhir
14
14
  require 'lifen_fhir/configuration'
15
15
  require 'lifen_fhir/base'
16
16
 
17
+ require 'lifen_fhir/address'
17
18
  require 'lifen_fhir/channel'
18
19
  require 'lifen_fhir/practitioner'
19
20
  require 'lifen_fhir/category'
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://develop.lifen.fr/fhir/Patient
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"resourceType":"Patient","name":[{"family":"Potter","given":["Pierre","Henri"]}],"address":[{"line":["M
9
+ et Mme Potter","39 rue d''Aboukir"],"city":"paris","postalCode":"75002"}],"birthDate":"1974-12-25"}'
10
+ headers:
11
+ User-Agent:
12
+ - Faraday v0.12.1
13
+ Authorization:
14
+ - Bearer valid_application_access_token
15
+ Accept:
16
+ - application/json
17
+ Content-Type:
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: 201
24
+ message: Created
25
+ headers:
26
+ Server:
27
+ - Apache-Coyote/1.1
28
+ X-B3-Sampled:
29
+ - '1'
30
+ X-B3-Spanid:
31
+ - db5383adf72065bc
32
+ X-B3-Traceid:
33
+ - db5383adf72065bc
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.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
46
+ Location:
47
+ - http://rc2.lifen.fr:10134/fhir/OperationOutcome/ab7002e2-f017-48a5-ae09-1e232dc7c726
48
+ Content-Type:
49
+ - application/json+fhir;charset=UTF-8
50
+ Transfer-Encoding:
51
+ - chunked
52
+ Date:
53
+ - Wed, 24 May 2017 13:52:59 GMT
54
+ body:
55
+ encoding: UTF-8
56
+ string: |-
57
+ {
58
+ "resourceType": "OperationOutcome",
59
+ "id": "ab7002e2-f017-48a5-ae09-1e232dc7c726",
60
+ "issue": [
61
+ {
62
+ "severity": "information",
63
+ "diagnostics": "Patient created."
64
+ }
65
+ ]
66
+ }
67
+ http_version:
68
+ recorded_at: Wed, 24 May 2017 13:53:00 GMT
69
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/fhir/Patient/ab7002e2-f017-48a5-ae09-1e232dc7c726
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-Sampled:
26
+ - '1'
27
+ X-B3-Spanid:
28
+ - 218872f87cb44505
29
+ X-B3-Traceid:
30
+ - 218872f87cb44505
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ Cache-Control:
36
+ - no-cache, no-store, max-age=0, must-revalidate
37
+ Pragma:
38
+ - no-cache
39
+ Expires:
40
+ - '0'
41
+ X-Powered-By:
42
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
43
+ Location:
44
+ - http://rc2.lifen.fr:10134/fhir/Patient/ab7002e2-f017-48a5-ae09-1e232dc7c726
45
+ Content-Type:
46
+ - application/json+fhir;charset=UTF-8
47
+ Transfer-Encoding:
48
+ - chunked
49
+ Date:
50
+ - Wed, 24 May 2017 13:53:45 GMT
51
+ body:
52
+ encoding: UTF-8
53
+ string: |-
54
+ {
55
+ "resourceType": "Patient",
56
+ "id": "ab7002e2-f017-48a5-ae09-1e232dc7c726",
57
+ "name": [
58
+ {
59
+ "family": "Potter",
60
+ "given": [
61
+ "Pierre",
62
+ "Henri"
63
+ ]
64
+ }
65
+ ],
66
+ "birthDate": "1974-12-25",
67
+ "address": [
68
+ {
69
+ "line": [
70
+ "M et Mme Potter",
71
+ "39 rue d'Aboukir"
72
+ ],
73
+ "city": "paris",
74
+ "postalCode": "75002",
75
+ "country": "France"
76
+ }
77
+ ]
78
+ }
79
+ http_version:
80
+ recorded_at: Wed, 24 May 2017 13:53:46 GMT
81
+ 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/Patient/wrong-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-Sampled:
26
+ - '1'
27
+ X-B3-Spanid:
28
+ - feefdc6792efdd5e
29
+ X-B3-Traceid:
30
+ - feefdc6792efdd5e
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ Cache-Control:
36
+ - no-cache, no-store, max-age=0, must-revalidate
37
+ Pragma:
38
+ - no-cache
39
+ Expires:
40
+ - '0'
41
+ X-Powered-By:
42
+ - HAPI FHIR 2.4 REST Server (FHIR Server; FHIR 3.0.1/DSTU3)
43
+ Content-Type:
44
+ - application/json+fhir;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Wed, 24 May 2017 13:53:00 GMT
49
+ body:
50
+ encoding: UTF-8
51
+ string: |-
52
+ {
53
+ "resourceType": "OperationOutcome",
54
+ "issue": [
55
+ {
56
+ "severity": "error",
57
+ "code": "processing",
58
+ "diagnostics": "Resource Patient/wrong-uuid is not known"
59
+ }
60
+ ]
61
+ }
62
+ http_version:
63
+ recorded_at: Wed, 24 May 2017 13:53:00 GMT
64
+ recorded_with: VCR 3.0.3
@@ -15,7 +15,7 @@ describe LifenFhir::CommunicationRequest do
15
15
 
16
16
  let(:attachment) { LifenFhir::Attachment.new(title: "Master Plan", path: File.dirname(__FILE__) + "/support/master_plan.pdf", content_type: "application/pdf") }
17
17
 
18
- let(:patient) { LifenFhir::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1)) }
18
+ let(:patient) { LifenFhir::Patient.new(first_name: "Jean", last_name: "Dupond", birth_date: Date.new(2000,1,1)) }
19
19
 
20
20
 
21
21
 
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe LifenFhir::Patient do
4
+
5
+ describe ':create' do
6
+
7
+ it 'works' do
8
+
9
+ address = LifenFhir::Address.new(
10
+ lines: ["M et Mme Potter", "39 rue d'Aboukir"],
11
+ city:"paris",
12
+ postal_code: "75002"
13
+ )
14
+
15
+ patient = LifenFhir::Patient.new(
16
+ first_name: ["Pierre", "Henri"],
17
+ last_name: "Potter",
18
+ birth_date: Date.new(1974, 12, 25),
19
+ address: address
20
+ )
21
+
22
+ VCR.use_cassette "patient/create/with_all_information" do
23
+ patient.save
24
+ end
25
+
26
+ expect(patient.uuid).to eq("ab7002e2-f017-48a5-ae09-1e232dc7c726")
27
+ end
28
+
29
+ end
30
+
31
+ describe ':find_by_uuid' do
32
+
33
+ it 'works' do
34
+ VCR.use_cassette "patient/find/with_valid_id" do
35
+ @patient = LifenFhir::Patient.find_by_uuid("ab7002e2-f017-48a5-ae09-1e232dc7c726")
36
+ end
37
+
38
+ expect(@patient.last_name).to eq("Potter")
39
+ expect(@patient.first_name).to eq(["Pierre", "Henri"])
40
+ expect(@patient.birth_date).to eq(Date.new(1974, 12, 25))
41
+
42
+ address = @patient.address
43
+
44
+ expect(address.postal_code).to eq("75002")
45
+ expect(address.city).to eq("paris")
46
+ expect(address.lines.size).to eq(2)
47
+ end
48
+
49
+ it 'wrong uuid' do
50
+
51
+ VCR.use_cassette "patient/find/with_wrong_id" do
52
+ expect {
53
+ @patient = LifenFhir::Patient.find_by_uuid("wrong-uuid")
54
+ }.to raise_error LifenFhir::Error
55
+ end
56
+ end
57
+
58
+ end
59
+ 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.1.1
4
+ version: 0.2.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-05-23 00:00:00.000000000 Z
12
+ date: 2017-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -154,6 +154,7 @@ files:
154
154
  - License.txt
155
155
  - README.md
156
156
  - lib/lifen_fhir.rb
157
+ - lib/lifen_fhir/address.rb
157
158
  - lib/lifen_fhir/app_authenticated_client.rb
158
159
  - lib/lifen_fhir/attachment.rb
159
160
  - lib/lifen_fhir/base.rb
@@ -177,6 +178,9 @@ files:
177
178
  - spec/cassettes/communication_request/send/invalid_medium.yml
178
179
  - spec/cassettes/communication_request/send/valid_attributes.yml
179
180
  - spec/cassettes/communication_request/send/valid_attributes_binary.yml
181
+ - spec/cassettes/patient/create/with_all_information.yml
182
+ - spec/cassettes/patient/find/with_valid_id.yml
183
+ - spec/cassettes/patient/find/with_wrong_id.yml
180
184
  - spec/cassettes/practitionner/create_channel/address/old_valid_attributes.yml
181
185
  - spec/cassettes/practitionner/create_channel/address/valid_attributes.yml
182
186
  - spec/cassettes/practitionner/create_channel/telecom/valid_attributes.yml
@@ -185,6 +189,7 @@ files:
185
189
  - spec/cassettes/practitionner/find_by_rpps/wrong_rpps.yml
186
190
  - spec/category_spec.rb
187
191
  - spec/communication_request_spec.rb
192
+ - spec/patient_spec.rb
188
193
  - spec/practitionner_spec.rb
189
194
  - spec/spec_helper.rb
190
195
  - spec/support/master_plan.pdf
@@ -208,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
213
  version: '0'
209
214
  requirements: []
210
215
  rubyforge_project:
211
- rubygems_version: 2.6.11
216
+ rubygems_version: 2.5.2
212
217
  signing_key:
213
218
  specification_version: 4
214
219
  summary: Lifen FHIR API Ruby client
@@ -219,6 +224,9 @@ test_files:
219
224
  - spec/cassettes/communication_request/send/invalid_medium.yml
220
225
  - spec/cassettes/communication_request/send/valid_attributes.yml
221
226
  - spec/cassettes/communication_request/send/valid_attributes_binary.yml
227
+ - spec/cassettes/patient/create/with_all_information.yml
228
+ - spec/cassettes/patient/find/with_valid_id.yml
229
+ - spec/cassettes/patient/find/with_wrong_id.yml
222
230
  - spec/cassettes/practitionner/create_channel/address/old_valid_attributes.yml
223
231
  - spec/cassettes/practitionner/create_channel/address/valid_attributes.yml
224
232
  - spec/cassettes/practitionner/create_channel/telecom/valid_attributes.yml
@@ -227,6 +235,7 @@ test_files:
227
235
  - spec/cassettes/practitionner/find_by_rpps/wrong_rpps.yml
228
236
  - spec/category_spec.rb
229
237
  - spec/communication_request_spec.rb
238
+ - spec/patient_spec.rb
230
239
  - spec/practitionner_spec.rb
231
240
  - spec/spec_helper.rb
232
241
  - spec/support/master_plan.pdf