Module: EVSSClaimTimelineHelper
- Included in:
- EVSSClaimDetailSerializer
- Defined in:
- app/serializers/evss_claim_timeline_helper.rb
Constant Summary collapse
- TRACKED_ITEM_FIELDS =
%w[ never_received_from_others_list never_received_from_you_list received_from_others_list received_from_you_list still_need_from_you_list still_need_from_others_list ].freeze
- EVENT_DATE_FIELDS =
Order of EVENT_DATE_FIELDS determines which date trumps in timeline sorting
%i[ closed_date received_date upload_date opened_date requested_date suspense_date ].freeze
Instance Method Summary collapse
- #create_documents(objs) ⇒ Object private
- #create_event_from_string_date(type, date) ⇒ Object private
- #create_events_for_documents(object) ⇒ Object private
- #create_events_for_tracked_items(object) ⇒ Object private
- #create_tracked_item_event(type, obj) ⇒ Object private
- #date_or_nil_from(obj, key, format: '%m/%d/%Y') ⇒ Object private
- #events_timeline(object) ⇒ Object
- #latest_upload_date(documents) ⇒ Object private
- #sub_objects_of(object) ⇒ Object private
Instance Method Details
#create_documents(objs) ⇒ Object (private)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 92 def create_documents(objs) objs.map do |obj| { tracked_item_id: obj['tracked_item_id'], file_type: obj['document_type_label'], document_type: obj['document_type_code'], filename: obj['original_file_name'], # %Q is the C-strftime flag for milliseconds since Unix epoch. # For date-times recording a computer event and therefore known # to the second EVSS uses a UNIX timestamp in milliseconds. # Round it to the day. Not sure what timezone they're using, # so could be off by 1 day. upload_date: date_or_nil_from(obj, 'upload_date', format: '%Q') } end end |
#create_event_from_string_date(type, date) ⇒ Object (private)
28 29 30 31 32 33 34 35 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 28 def create_event_from_string_date(type, date) return nil unless date { type:, date: Date.strptime(date, '%m/%d/%Y') } end |
#create_events_for_documents(object) ⇒ Object (private)
50 51 52 53 54 55 56 57 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 50 def create_events_for_documents(object) # Objects with trackedItemId are part of other events, so don't duplicate them docs = sub_objects_of(object, 'vba_document_list').select { |obj| obj['tracked_item_id'].nil? } docs = create_documents docs docs.map do |obj| obj.merge(type: :other_documents_list, date: obj[:upload_date]) end end |
#create_events_for_tracked_items(object) ⇒ Object (private)
42 43 44 45 46 47 48 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 42 def create_events_for_tracked_items(object) TRACKED_ITEM_FIELDS.map do |field| sub_objects_of(object, 'claim_tracked_items', field).map do |obj| create_tracked_item_event(field.underscore, obj) end end.flatten end |
#create_tracked_item_event(type, obj) ⇒ Object (private)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 69 def create_tracked_item_event(type, obj) documents = create_documents(obj['vba_documents'] || []) event = { type:, tracked_item_id: obj['tracked_item_id'], description: ActionView::Base.full_sanitizer.sanitize(obj['description']), display_name: obj['displayed_name'], overdue: obj['overdue'], status: obj['tracked_item_status'], uploaded: obj['uploaded'], uploads_allowed: obj['uploads_allowed'], opened_date: date_or_nil_from(obj, 'opened_date'), requested_date: date_or_nil_from(obj, 'requested_date'), received_date: date_or_nil_from(obj, 'received_date'), closed_date: date_or_nil_from(obj, 'closed_date'), suspense_date: date_or_nil_from(obj, 'suspense_date'), documents:, upload_date: latest_upload_date(documents) } event[:date] = event.slice(*EVENT_DATE_FIELDS).values.compact.first event end |
#date_or_nil_from(obj, key, format: '%m/%d/%Y') ⇒ Object (private)
114 115 116 117 118 119 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 114 def date_or_nil_from(obj, key, format: '%m/%d/%Y') date = obj[key] return nil if date.blank? Date.strptime(date.to_s, format) end |
#events_timeline(object) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 4 def events_timeline(object) events = [ create_event_from_string_date(:filed, object.data['date']), create_event_from_string_date(:completed, object.data['claim_complete_date']) ] # Do the 8 phases (1..8).each do |n| date = object.data.dig('claim_phase_dates', "phase#{n}_complete_date") events << create_event_from_string_date("phase#{n}", date) end # Add tracked items events += create_events_for_tracked_items(object) # Add documents not associated with a tracked item events += create_events_for_documents(object) # Make reverse chron with nil date items at the end events.compact.sort_by { |h| h[:date] || Date.new }.reverse end |
#latest_upload_date(documents) ⇒ Object (private)
121 122 123 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 121 def latest_upload_date(documents) documents.pluck(:upload_date).sort.reverse.first end |
#sub_objects_of(object) ⇒ Object (private)
109 110 111 112 |
# File 'app/serializers/evss_claim_timeline_helper.rb', line 109 def sub_objects_of(object, *) items = object.data.dig(*) || [] items.compact end |