Class: SnomedQuery::CodeSystem

Inherits:
Object
  • Object
show all
Extended by:
Http
Defined in:
lib/snomed_query/code_system.rb

Class Method Summary collapse

Methods included from Http

client

Class Method Details

.build_fhir_uri(identifier) ⇒ Object



28
29
30
31
32
33
# File 'lib/snomed_query/code_system.rb', line 28

def build_fhir_uri(identifier)
  URI::HTTP.build(
    path: "/fhir/CodeSystem/$lookup",
    query: "url=#{SNOMED_VARIANT}&code=#{identifier}"
  )
end

.handle_response(response) ⇒ Object

Raises:



21
22
23
24
25
26
# File 'lib/snomed_query/code_system.rb', line 21

def handle_response(response)
  parsed_response = JSON.parse(response.body).transform_keys(&:to_sym)
  return Parameter.new(**parsed_response) if response.success?

  raise SnomedQuery::Error, OperationOutcome.new(**parsed_response).error_message
end

.lookup(identifier) ⇒ Object



8
9
10
11
12
# File 'lib/snomed_query/code_system.rb', line 8

def lookup(identifier)
  uri = build_fhir_uri(identifier)
  response = client.get(uri.request_uri)
  handle_response(response)
end

.synonyms(identifier) ⇒ Object



14
15
16
17
18
19
# File 'lib/snomed_query/code_system.rb', line 14

def synonyms(identifier)
  JSON.parse(
    lookup(identifier).parameter.to_json,
    object_class: CustomStruct
  ).collect(&:syn).flatten
end