Class: LifenFhir::Patient

Inherits:
Element show all
Defined in:
lib/lifen_fhir/patient.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#fhir_payload_as_reference, #reference

Class Method Details

.create(params) ⇒ Object



10
11
12
# File 'lib/lifen_fhir/patient.rb', line 10

def self.create(params)
  new(params).save
end

.find_by_uuid(uuid) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/lifen_fhir/patient.rb', line 22

def self.find_by_uuid(uuid)
  patient = new(uuid:uuid)

  json = application_client.get("fhir/#{patient.reference}")

  patient.attributes_from_json(json)

  patient
end

Instance Method Details

#attributes_from_json(json) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lifen_fhir/patient.rb', line 47

def attributes_from_json(json)
  self.uuid = json["id"]

  full_name = Array(json["name"]).first

  self.first_name = Array(full_name["given"])
  self.last_name = full_name["family"]

  self.birth_date = json["birthDate"]

  address_json = json["address"].first
  self.address = Address.new.attributes_from_json(address_json)
end

#fhir_payloadObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lifen_fhir/patient.rb', line 32

def fhir_payload
  fhir_payload = {
    id: "patient",
    resourceType: "Patient",
    name: [
      {
        family: last_name,
        given: first_name
      }
    ]
  }
  fhir_payload[:birthDate] = birth_date.to_s if birth_date
  fhir_payload
end

#saveObject



14
15
16
17
18
19
20
# File 'lib/lifen_fhir/patient.rb', line 14

def save
  json = application_client.post("fhir/Patient", create_payload)

  self.uuid = json["id"]

  self
end