Class: HealthCards::HealthCard

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/health_cards/health_card.rb

Overview

Represents a signed SMART Health Card

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jws) ⇒ HealthCard

Create a HealthCard from a JWS

Parameters:

  • jws (JWS, String)

    A JWS object or JWS string



15
16
17
18
19
# File 'lib/health_cards/health_card.rb', line 15

def initialize(jws)
  @jws = JWS.from_jws(jws)
  @payload = Payload.from_payload(@jws.payload)
  @qr_codes = QRCodes.from_jws(@jws)
end

Instance Attribute Details

#jwsObject (readonly)

Returns the value of attribute jws.



8
9
10
# File 'lib/health_cards/health_card.rb', line 8

def jws
  @jws
end

Instance Method Details

#qr_codesArray<Chunk>

QR Codes representing this HealthCard

Returns:

  • (Array<Chunk>)

    an array of QR Code chunks



29
30
31
# File 'lib/health_cards/health_card.rb', line 29

def qr_codes
  @qr_codes.chunks
end

#resource(type: nil, &block) ⇒ Object

Extracts a resource from the bundle contained in the HealthCard. A filter can be applied by using a block. The method will yield each resource to the block. The block should return a boolean

Parameters:

  • type (Class) (defaults to: nil)

    :type should be a class representing a FHIR resource

Returns:

  • The first bundle resource that matches the type and/or block evaluation



38
39
40
# File 'lib/health_cards/health_card.rb', line 38

def resource(type: nil, &block)
  resources(type: type, &block).first
end

#resources(type: nil, &block) ⇒ Object

Extracts all resources from the bundle contained in the HealthCard. A filter can be applied by using a block. The method will yield each resource to the block. The block should return a boolean

Parameters:

  • type (Class) (defaults to: nil)

    :type should be a class representing a FHIR resource

Returns:

  • The first bundle resource that matches the type and/or block evaluation



47
48
49
50
51
52
53
54
# File 'lib/health_cards/health_card.rb', line 47

def resources(type: nil, &block)
  all_resources = bundle.entry.map(&:resource)
  return all_resources unless type || block

  all_resources.filter do |r|
    resource_matches_criteria(r, type, &block)
  end
end

#to_json(*_args) ⇒ String

Export HealthCard as JSON, formatted for file downloads

Returns:

  • (String)

    JSON string containing file download contents



23
24
25
# File 'lib/health_cards/health_card.rb', line 23

def to_json(*_args)
  Exporter.file_download([@jws])
end