Module: FHIR::ReferenceExtras

Included in:
DSTU2::Reference, Reference, STU3::Reference
Defined in:
lib/fhir_client/ext/reference.rb

Instance Method Summary collapse

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/fhir_client/ext/reference.rb', line 22

def absolute?
  /^https?:\/\//.match reference.to_s
end

#base_uriObject



52
53
54
55
# File 'lib/fhir_client/ext/reference.rb', line 52

def base_uri
  return if !absolute? || contained?
  parts[:base_uri]
end

#contained?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fhir_client/ext/reference.rb', line 18

def contained?
  reference.to_s.start_with?('#')
end

#has_version?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fhir_client/ext/reference.rb', line 30

def has_version?
  /_history/.match reference.to_s
end

#partsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fhir_client/ext/reference.rb', line 3

def parts
  return if contained?
  if has_version?
    *base_uri, type, id, _, version = reference.to_s.split '/'
  else
    *base_uri, type, id = reference.to_s.split '/'
  end
  {
    base_uri: (base_uri.empty?) ? nil : base_uri.join('/'),
    type: type,
    id: id,
    version: version
  }
end

#read(client = self.client) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/fhir_client/ext/reference.rb', line 57

def read(client = self.client)
  return if !(relative? || absolute?)
  if relative? || reference == client.full_resource_url(resource: resource_class, id: reference_id)
    read_client = client
  else
    read_client = FHIR::Client.new base_uri, default_format: client.default_format, proxy: client.proxy
  end
  resource_class.read(reference_id, read_client)
end

#reference_idObject



34
35
36
37
38
39
40
# File 'lib/fhir_client/ext/reference.rb', line 34

def reference_id
  if contained?
    reference.to_s[1..-1]
  else
    parts[:id]
  end
end

#relative?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fhir_client/ext/reference.rb', line 26

def relative?
  !(reference.blank? || contained? || absolute?)
end

#resource_typeObject



42
43
44
45
# File 'lib/fhir_client/ext/reference.rb', line 42

def resource_type
  return if contained?
  parts[:type]
end

#version_idObject



47
48
49
50
# File 'lib/fhir_client/ext/reference.rb', line 47

def version_id
  return if contained?
  parts[:version]
end

#vread(client = self.client) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/fhir_client/ext/reference.rb', line 67

def vread(client = self.client)
  return if !(relative? || absolute?) || version_id.blank?
  if relative? || reference == client.full_resource_url(resource: resource_class, id: reference_id)
    read_client = client
  else
    read_client = FHIR::Client.new base_uri, default_format: client.default_format, proxy: client.proxy
  end
  resource_class.vread(reference_id, version_id, read_client)
end