Class: FHIR::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.conditional_create(model, params, client = self.client) ⇒ Object



41
42
43
44
# File 'lib/ext/model.rb', line 41

def self.conditional_create(model, params, client = self.client)
  model = new(model) unless model.is_a?(self)
  client.conditional_create(model, params)
end

.create(model, client = self.client) ⇒ Object



36
37
38
39
# File 'lib/ext/model.rb', line 36

def self.create(model, client = self.client)
  model = new(model) unless model.is_a?(self)
  client.create(model).resource
end

.read(id, client = self.client) ⇒ Object



24
25
26
# File 'lib/ext/model.rb', line 24

def self.read(id, client = self.client)
  client.read(self, id).resource
end

.read_with_summary(id, summary, client = self.client) ⇒ Object



28
29
30
# File 'lib/ext/model.rb', line 28

def self.read_with_summary(id, summary, client = self.client)
  client.read(self, id, client.default_format, summary).resource
end

.search(params = {}, client = self.client) ⇒ Object



32
33
34
# File 'lib/ext/model.rb', line 32

def self.search(params = {}, client = self.client)
  client.search(self, search: { parameters: params }).resource
end

Instance Method Details

#clientObject



7
8
9
# File 'lib/ext/model.rb', line 7

def client
  @client || self.class.client
end

#client=(client) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ext/model.rb', line 11

def client=(client)
  @client = client

  # Ensure the client-setting cascades to all child models
  instance_values.each do |_key, values|
    Array.wrap(values).each do |value|
      next unless value.is_a?(FHIR::Model)
      next if value.client == client
      value.client = client
    end
  end
end

#conditional_create(params) ⇒ Object



50
51
52
# File 'lib/ext/model.rb', line 50

def conditional_create(params)
  client.conditional_create(self, params)
end

#conditional_update(params) ⇒ Object



58
59
60
# File 'lib/ext/model.rb', line 58

def conditional_update(params)
  client.conditional_update(self, self.id, params).resource
end

#createObject



46
47
48
# File 'lib/ext/model.rb', line 46

def create
  client.create(self).resource
end

#destroyObject



62
63
64
65
# File 'lib/ext/model.rb', line 62

def destroy
  client.destroy(self.class, id) unless id.nil?
  nil
end

#updateObject



54
55
56
# File 'lib/ext/model.rb', line 54

def update
  client.update(self, id).resource
end