Skip to content

Commit

Permalink
add claim event timeline model
Browse files Browse the repository at this point in the history
  • Loading branch information
aherzberg committed Apr 25, 2024
1 parent 024e9b3 commit 26637d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def get_claim
else
evss_claims_proxy.get_claim(params[:id])
end
binding.pry

render json: Mobile::V0::ClaimSerializer.new(claim_detail)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def parse(claim)
attributes = claim.dig('data', 'attributes')
phase_change_date = attributes.dig('claimPhaseDates', 'phaseChangeDate')
events_timeline = events_timeline(attributes)
binding.pry

Mobile::V0::Claim.new(
{
Expand Down Expand Up @@ -113,7 +112,7 @@ def events_timeline(attributes)

# sort to put events with uploaded == false on top and then by date
events.compact.sort_by do |event|
upload_priority = if event.try(:uploaded) || event.try(:uploaded).nil?
upload_priority = if event.uploaded || event.uploaded.nil?
0 # Lower priority for uploaded == true or key not present
else
1 # Higher priority for uploaded == false
Expand Down Expand Up @@ -159,11 +158,15 @@ def create_events_for_tracked_items(attributes)

def create_events_for_documents(attributes)
untracked_documents = attributes['supportingDocuments'].select { |document| document['trackedItemId'].nil? }
create_documents(untracked_documents, false)
untracked_documents.map do |document|
date = document[:upload_date] ? Date.strptime(document[:upload_date], '%Y-%m-%d') : nil
create_event_from_string_date(:other_documents_list, date)
end

end

def create_tracked_item_event(tracked_item, tracked_item_documents)
documents = create_documents(tracked_item_documents, true)
documents = create_documents(tracked_item_documents)

event = {
type: LH_STATUS_TO_EVSS_TYPE[tracked_item['status'].to_sym],
Expand All @@ -187,7 +190,7 @@ def create_tracked_item_event(tracked_item, tracked_item_documents)
ClaimEventTimeline.new(event)
end

def create_documents(documents, tracked)
def create_documents(documents)
documents.map do |document|
document_hash = {
tracked_item_id: document['trackedItemId'],
Expand All @@ -196,13 +199,7 @@ def create_documents(documents, tracked)
document_type: nil,
filename: document['originalFileName'],
upload_date: document['uploadDate'],
type: nil,
date: nil
}
unless tracked
date = document[:upload_date] ? Date.strptime(document[:upload_date], '%Y-%m-%d') : nil
document_hash.merge!(type: :other_documents_list, date:)
end
ClaimDocument.new(document_hash)
end
end
Expand Down
2 changes: 0 additions & 2 deletions modules/mobile/app/models/mobile/v0/claim_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ClaimDocument < Common::Resource
attribute :document_type, Types::Integer
attribute :filename, Types::String
attribute :upload_date, Types::Date
attribute :type, Types::String
attribute :date, Types::Date
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
VCR.use_cassette('mobile/lighthouse_claims/show/200_response') do
get '/mobile/v0/claim/600117255', headers: sis_headers
end
binding.pry

tracked_item_with_no_docs = response.parsed_body.dig('data', 'attributes', 'eventsTimeline').select do |event|
event['trackedItemId'] == 360_055
end.first
tracked_item_with_docs = response.parsed_body.dig('data', 'attributes', 'eventsTimeline').select do |event|
event['trackedItemId'] == 360_052
end.first
binding.pry

expect(response).to have_http_status(:ok)
expect(response.body).to match_json_schema('individual_claim', strict: true)
Expand All @@ -45,13 +45,10 @@
expect(tracked_item_with_no_docs['uploaded']).to eq(false)

uploaded_of_events = response.parsed_body.dig('data', 'attributes', 'eventsTimeline').pluck('uploaded').compact
date_of_events = response.parsed_body.dig('data', 'attributes', 'eventsTimeline').select do |event|
event['uploaded'] || !event.key?('uploaded')
end.pluck('date')
date_of_events = response.parsed_body.dig('data', 'attributes', 'eventsTimeline').pluck('date')

expect(uploaded_of_events).to eq([false, false, false, true, true, true, true, true])
expect(date_of_events).to eq(['2023-03-01', '2022-12-12', '2022-10-30', '2022-10-30', '2022-10-11',
'2022-09-30', '2022-09-30', '2022-09-27', nil, nil, nil, nil, nil, nil, nil, nil])
expect(date_of_events).to eq(["2022-10-30", "2022-10-30", "2022-09-30", "2023-03-01", "2022-12-12", "2022-10-30", "2022-10-30", "2022-10-11", "2022-09-30", "2022-09-30", "2022-09-27"])
end
end

Expand Down

0 comments on commit 26637d6

Please sign in to comment.