Module: FHIR::Sections::Operations

Included in:
Client
Defined in:
lib/fhir_client/sections/operations.rb

Instance Method Summary collapse

Instance Method Details

#closure_table_maintenance(params = {}, format = @default_format) ⇒ Object

ConceptMap Closure Table Maintenance



94
95
96
97
98
# File 'lib/fhir_client/sections/operations.rb', line 94

def closure_table_maintenance(params = {}, format = @default_format)
  options = { operation: { name: :closure_table_maintenance } }
  options.deep_merge!(params)
  terminology_operation(options, format)
end

#code_system_lookup(params = {}, format = @default_format) ⇒ Object

Concept Look Up [base]/CodeSystem/$lookup



75
76
77
78
79
80
81
82
83
84
# File 'lib/fhir_client/sections/operations.rb', line 75

def code_system_lookup(params = {}, format = @default_format)
  klass = if @fhir_version == :dstu2
            FHIR::DSTU2::ValueSet
          else
            self.versioned_resource_class(:CodeSystem)
          end
  options = { resource: klass, operation: { name: :code_system_lookup } }
  options.deep_merge!(params)
  terminology_operation(options, format)
end

#concept_map_translate(params = {}, format = @default_format) ⇒ Object

ConceptMap Translation



87
88
89
90
91
# File 'lib/fhir_client/sections/operations.rb', line 87

def concept_map_translate(params = {}, format = @default_format)
  options = { resource: versioned_resource_class('ConceptMap'), operation: { name: :concept_map_translate } }
  options.deep_merge!(params)
  terminology_operation(options, format)
end

#fetch_encounter_record(id = nil, method = 'GET', format = nil) ⇒ Object



17
18
19
# File 'lib/fhir_client/sections/operations.rb', line 17

def fetch_encounter_record(id = nil, method = 'GET', format = nil)
  fetch_record(id, [nil, nil], method, versioned_resource_class('Encounter'), format)
end

#fetch_patient_record(id = nil, startTime = nil, endTime = nil, method = 'GET', format = nil) ⇒ Object

Fetch Patient Record [base]/Patient/$everything | [base]/Patient//$everything hl7.org/implement/standards/FHIR-Develop/patient-operations.html#everything Fetches resources for a given patient record, scoped by a start and end time, and returns a Bundle of results



13
14
15
# File 'lib/fhir_client/sections/operations.rb', line 13

def fetch_patient_record(id = nil, startTime = nil, endTime = nil, method = 'GET', format = nil)
  fetch_record(id, [startTime, endTime], method, versioned_resource_class('Patient'), format)
end

#fetch_record(id = nil, time = [nil, nil], method = 'GET', klass = versioned_resource_class('Patient'), format = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fhir_client/sections/operations.rb', line 21

def fetch_record(id = nil, time = [nil, nil], method = 'GET', klass = versioned_resource_class('Patient'), format = nil)
  headers = {}
  headers[:accept] =  "#{format}" if format
  format ||= @default_format
  headers[:content_type] = format
  options = { resource: klass, format: format, operation: { name: :fetch_patient_record, method: method } }
  options.deep_merge!(id: id) unless id.nil?
  options[:operation][:parameters] = {} if options[:operation][:parameters].nil?
  options[:operation][:parameters][:start] = { type: 'Date', value: time.first } unless time.first.nil?
  options[:operation][:parameters][:end] = { type: 'Date', value: time.last } unless time.last.nil?

  if options[:operation][:method] == 'GET'
    reply = get resource_url(options), fhir_headers
  else
    # create Parameters body
    if options[:operation] && options[:operation][:parameters]
      p = versioned_resource_class('Parameters').new
      options[:operation][:parameters].each do |key, value|
        parameter = versioned_resource_class('Parameters::Parameter').new.from_hash(name: key.to_s)
        parameter.method("value#{value[:type]}=").call(value[:value])
        p.parameter << parameter
      end
    end
    reply = post resource_url(options), p, fhir_headers(headers)
  end

  reply.resource = parse_reply(versioned_resource_class('Bundle'), format, reply)
  reply.resource_class = options[:resource]
  reply
end

#match(resource, options = {}, format = @default_format) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/fhir_client/sections/operations.rb', line 129

def match(resource, options = {}, format = @default_format)
  options.merge!(resource: resource.class, match: true, format: format)
  params = versioned_resource_class('Parameters').new
  add_resource_parameter(params, 'resource', resource)
  add_parameter(params, 'onlyCertainMatches', 'Boolean', options[:onlyCertainMatches]) unless options[:onlyCertainMatches].nil?
  add_parameter(params, 'count', 'Integer', options[:matchCount]) if options[:matchCount].is_a?(Integer)
  post(
    resource_url(options),
    params,
    fhir_headers({content_type: "#{format || @default_format}", accept: "#{format || @default_format}"})
  ).tap { |reply| set_client_on_resource(reply.resource) }
end

#terminology_operation(params = {}, format = @default_format) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/fhir_client/sections/operations.rb', line 100

def terminology_operation(params = {}, format = @default_format)
  options = { format: format }
  headers = {}
  headers[:accept] =  "#{format}" if format
  format ||= @default_format
  # params = [id, code, system, version, display, coding, codeableConcept, date, abstract]
  options.deep_merge!(params)

  if options[:operation][:method] == 'GET'
    reply = get resource_url(options), fhir_headers(headers)
  else
    # create Parameters body
    if options[:operation] && options[:operation][:parameters]
      p = versioned_resource_class('Parameters').new
      options[:operation][:parameters].each do |key, value|
        parameter = versioned_resource_class('Parameters::Parameter').new.from_hash(name: key.to_s)
        parameter.method("value#{value[:type]}=").call(value[:value])
        p.parameter << parameter
      end
    end
    headers[:content_type] = "#{format}"
    reply = post resource_url(options), p, fhir_headers(headers)
  end

  reply.resource = parse_reply(options[:resource], format, reply)
  reply.resource_class = options[:resource]
  reply
end

#validate(resource, options = {}, format = @default_format) ⇒ Object

Validate resource payload.

public <T extends Resource> AtomEntry<OperationOutcome> validate(Class<T> resourceClass, T resource, String id);

Parameters:

  • resourceClass
  • resource
  • id

Returns:



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/fhir_client/sections/operations.rb', line 152

def validate(resource, options = {}, format = @default_format)
  options.merge!(resource: resource.class, validate: true, format: format)
  headers = {}
  headers[:accept] =  "#{format}" if format
  headers[:content_type] = "#{format}"
  params = versioned_resource_class('Parameters').new
  add_resource_parameter(params, 'resource', resource)
  add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
  post(resource_url(options), params, fhir_headers(headers))
    .tap { |reply| set_client_on_resource(reply.resource) }
end

#validate_existing(resource, id, options = {}, format = @default_format) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/fhir_client/sections/operations.rb', line 164

def validate_existing(resource, id, options = {}, format = @default_format)
  options.merge!(resource: resource.class, id: id, validate: true, format: format)
  headers = {}
  headers[:accept] =  "#{format}" if format
  headers[:content_type] = "#{format}"
  params = versioned_resource_class('Parameters').new
  add_resource_parameter(params, 'resource', resource)
  add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
  post(resource_url(options), params, fhir_headers(headers))
    .tap { |reply| set_client_on_resource(reply.resource) }
end

#value_set_code_validation(params = {}, format = @default_format) ⇒ Object

Value Set based Validation [base]/ValueSet/$validate | [base]/ValueSet//$validate hl7.org/implement/standards/FHIR-Develop/valueset-operations.html#validate Validate that a coded value is in the set of codes allowed by a value set.



68
69
70
71
72
# File 'lib/fhir_client/sections/operations.rb', line 68

def value_set_code_validation(params = {}, format = @default_format)
  options = { resource: versioned_resource_class('ValueSet'), operation: { name: :value_set_based_validation } }
  options.deep_merge!(params)
  terminology_operation(options, format)
end

#value_set_expansion(params = {}, format = @default_format) ⇒ Object

Value Set Expansion [base]/ValueSet/$expand | [base]/ValueSet//$expand hl7.org/implement/standards/FHIR-Develop/valueset-operations.html#expand The definition of a value set is used to create a simple collection of codes suitable for use for data entry or validation.



59
60
61
62
63
# File 'lib/fhir_client/sections/operations.rb', line 59

def value_set_expansion(params = {}, format = @default_format)
  options = { resource: versioned_resource_class('ValueSet'), operation: { name: :value_set_expansion } }
  options.deep_merge!(params)
  terminology_operation(options, format)
end