Class: CARMA::Models::Submission

Inherits:
Base
  • Object
show all
Defined in:
lib/carma/models/submission.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

after_to_request_payload, request_payload_key, #to_request_payload

Constructor Details

#initialize(args = {}) ⇒ Submission

Returns a new instance of Submission.



39
40
41
42
43
44
# File 'lib/carma/models/submission.rb', line 39

def initialize(args = {})
  self.carma_case_id = args[:carma_case_id]
  self. = args[:submitted_at]
  self.data = args[:data]
  self. = args[:metadata] || {}
end

Instance Attribute Details

#carma_case_idObject

Returns the value of attribute carma_case_id.



10
11
12
# File 'lib/carma/models/submission.rb', line 10

def carma_case_id
  @carma_case_id
end

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/carma/models/submission.rb', line 10

def data
  @data
end

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/carma/models/submission.rb', line 9

def 
  @metadata
end

#request_bodyObject (readonly)

Returns the value of attribute request_body.



9
10
11
# File 'lib/carma/models/submission.rb', line 9

def request_body
  @request_body
end

#submitted_atObject

Returns the value of attribute submitted_at.



10
11
12
# File 'lib/carma/models/submission.rb', line 10

def 
  @submitted_at
end

Class Method Details

.from_claim(claim, metadata = {}) ⇒ CARMA::Models::Submission

Returns a new CARMA::Models::Submission built from a CaregiversAssistanceClaim.

Parameters:

  • claim (CaregiversAssistanceClaim)

    A validated CaregiversAssistanceClaim

  • metadata (Hash) (defaults to: {})

    Additional data that can be submitted along with the claim’s form data

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/carma/models/submission.rb', line 21

def self.from_claim(claim,  = {})
  if Flipper.enabled?(:caregiver_carma_submitted_at)
    return new(
      data: claim.parsed_form,
      metadata: .merge(
        claim_id: claim.id,
        claim_guid: claim.guid,
        submitted_at: claim.created_at&.iso8601
      )
    )
  end

  new(
    data: claim.parsed_form,
    metadata: .merge(claim_id: claim.id, claim_guid: claim.guid)
  )
end

Instance Method Details

#submit!(client) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/carma/models/submission.rb', line 46

def submit!(client)
  raise 'This submission has already been submitted to CARMA' if 

  @request_body = to_request_payload

  response = client.create_submission(request_body)

  @carma_case_id = response['data']['carmacase']['id']
  @submitted_at = response['data']['carmacase']['createdAt']

  self
end

#submitted?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/carma/models/submission.rb', line 59

def 
  @submitted_at.present? || @carma_case_id.present?
end