Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stimulus reflex, navigation and curam check payload feature #49

Merged
merged 18 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .docker/config/cable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
development:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: medicaid_gateway_development

test:
adapter: async
url: redis://localhost:6379/1
channel_prefix: medicaid_gateway_test

production:
adapter: redis
url: redis://<%= ENV['REDIS_HOST_MEDICAID_GATEWAY'] %>:6379/1
channel_prefix: medicaid_gateway_production
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"[ruby]": {
"editor.defaultFormatter": "castwide.solargraph"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ gem 'jbuilder', '~> 2.7'
gem 'bootstrap', '~> 5.1.0'
# To prettify json payloads
gem 'awesome_print'
# For interactive pieces
gem "stimulus_reflex", "~> 3.4"

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
Expand Down Expand Up @@ -78,4 +80,4 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :production do
gem 'eye', '0.10.0'
gem 'unicorn', '~> 4.8'
end
end
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ideacrew/aca_entities.git
revision: acccd54c96e8d9ef48e239a56ecd2b6536e88ff2
revision: d75fcd7f3e17c351324fbccdf69eb0eb0a932614
branch: release_0.10.0
specs:
aca_entities (0.9.0)
Expand Down Expand Up @@ -162,6 +162,9 @@ GEM
amq-protocol (~> 2.3, >= 2.3.1)
sorted_set (~> 1, >= 1.0.2)
byebug (11.1.3)
cable_ready (4.5.0)
rails (>= 5.2)
thread-local (>= 1.1.0)
capybara (3.35.3)
addressable
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -492,7 +495,14 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
state_machines (0.5.0)
stimulus_reflex (3.4.1)
cable_ready (>= 4.5)
nokogiri
rack
rails (>= 5.2)
redis
thor (1.1.0)
thread-local (1.1.0)
tilt (2.0.10)
timers (4.3.3)
turbolinks (5.2.1)
Expand Down Expand Up @@ -561,6 +571,7 @@ DEPENDENCIES
sass-rails (>= 6)
shoulda-matchers (~> 3)
spring (~> 1.7.2)
stimulus_reflex (~> 3.4)
turbolinks (~> 5)
typhoeus
tzinfo-data
Expand Down
25 changes: 25 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
@import "bootstrap";

kbd {
-moz-background-clip: border;
-moz-background-inline-policy: continuous;
-moz-background-origin: padding;
background: #ffffff none repeat scroll 0 0;
border: none;
color: #000000;
padding: 2px 1px;
white-space: nowrap;
}

.long-payload {
display: -webkit-box;
-webkit-line-clamp: 10;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}

.table-overrides {
table-layout: fixed;
width: 100%;
word-wrap: break-word;
}
8 changes: 8 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

module ApplicationCable

# stimulus reflex connection differentiator
class Connection < ActionCable::Connection::Base
identified_by :session_id

def connect
self.session_id = request.session.id
reject_unauthorized_connection unless session_id
end
end
end
11 changes: 11 additions & 0 deletions app/controllers/medicaid/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Medicaid
# Determinations from MITC
class ApplicationsController < ActionController::Base
def show
@application = Medicaid::Application.find(params[:id])
render layout: "application"
end
end
end
75 changes: 54 additions & 21 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,49 @@
# ReportsController provides API access to reports
class ReportsController < ApplicationController

def events
@start_on = start_on || session[:start] || Date.today
@end_on = end_on || session[:end] || Date.today
events = applications + transfers + inbound_transfers + checks
@events = events.map(&:to_event).sort_by { |event| event[:created_at] }.reverse
end

def medicaid_applications
range = range_from_params
applications = Medicaid::Application.where(created_at: range).or(updated_at: range)
render json: applications
render json: Medicaid::Application.where(created_at: range_from_params).or(updated_at: range_from_params)
end

def medicaid_application_check
@range = range_from_params
@applications = Medicaid::Application.where(created_at: @range).or(updated_at: @range)
@start_on = start_on || session[:ma_start] || Date.today
@end_on = end_on || session[:ma_end] || Date.today
@applications = applications
end

def account_transfers
@range = range_from_params
@transfers = Aces::Transfer.where(created_at: @range).or(updated_at: @range)
@start_on = start_on || session[:atp_start] || Date.today
@end_on = end_on || session[:atp_end] || Date.today
@transfers = transfers
end

def account_transfers_to_enroll
@range = range_from_params
@transfers = Aces::InboundTransfer.where(created_at: @range).or(updated_at: @range)
@start_on = start_on || session[:atp_start] || Date.today
@end_on = end_on || session[:atp_end] || Date.today
@transfers = inbound_transfers
end

def mec_checks
@range = range_from_params
@checks = Aces::MecCheck.where(created_at: @range).or(updated_at: @range)
@start_on = start_on || session[:mc_sent_start] || Date.today
@end_on = session[:mc_sent_end] || Date.today
@checks = checks
end

def transfer_summary
@range = range_from_params
@start_on = params.fetch(:start_on) if params.key?(:start_on)
@end_on = params.fetch(:end_on) if params.key?(:end_on)
at_sent = Aces::Transfer.where(created_at: @range).or(updated_at: @range)
@at_sent_total = at_sent.count
@at_sent_successful = at_sent.where(failure: nil).count
@start_on = start_on || session[:atp_start] || Date.today
@end_on = end_on || session[:atp_end] || Date.today
@at_sent_total = transfers.count
@at_sent_successful = transfers.where(failure: nil).count
@at_sent_failure = @at_sent_total - @at_sent_successful

at_received = Aces::InboundTransfer.where(created_at: @range).or(updated_at: @range)
@at_received_total = at_received.count
@at_received_successful = at_received.where(failure: nil).count
@at_received_total = inbound_transfers.count
@at_received_successful = inbound_transfers.where(failure: nil).count
@at_received_failure = @at_received_total - @at_received_successful
end

Expand All @@ -51,4 +56,32 @@ def range_from_params
end_on = params.key?(:end_on) ? Date.strptime(params.fetch(:end_on), "%m/%d/%Y") : Time.now.utc
start_on.beginning_of_day..end_on.end_of_day
end

def start_on
Date.strptime(params.fetch(:start_on), "%m/%d/%Y") if params.key?(:start_on)
end

def end_on
Date.strptime(params.fetch(:end_on), "%m/%d/%Y") if params.key?(:end_on)
end

def range
@start_on.beginning_of_day..@end_on.end_of_day
end

def applications
Medicaid::Application.where(created_at: range).or(updated_at: range)
end

def transfers
Aces::Transfer.where(created_at: range).or(updated_at: range)
end

def inbound_transfers
Aces::InboundTransfer.where(created_at: range).or(updated_at: range)
end

def checks
Aces::MecCheck.where(created_at: range).or(updated_at: range)
end
end
60 changes: 60 additions & 0 deletions app/javascript/controllers/application_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'

/* This is your ApplicationController.
* All StimulusReflex controllers should inherit from this class.
*
* Example:
*
* import ApplicationController from './application_controller'
*
* export default class extends ApplicationController { ... }
*
* Learn more at: https://docs.stimulusreflex.com
*/
export default class extends Controller {
connect () {
StimulusReflex.register(this)
}

/* Application-wide lifecycle methods
*
* Use these methods to handle lifecycle concerns for the entire application.
* Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
*
* Arguments:
*
* element - the element that triggered the reflex
* may be different than the Stimulus controller's this.element
*
* reflex - the name of the reflex e.g. "Example#demo"
*
* error/noop - the error message (for reflexError), otherwise null
*
* reflexId - a UUID4 or developer-provided unique identifier for each Reflex
*/

beforeReflex (element, reflex, noop, reflexId) {
// document.body.classList.add('wait')
}

reflexSuccess (element, reflex, noop, reflexId) {
// show success message
}

reflexError (element, reflex, error, reflexId) {
// show error message
}

reflexHalted (element, reflex, error, reflexId) {
// handle aborted Reflex action
}

afterReflex (element, reflex, noop, reflexId) {
// document.body.classList.remove('wait')
}

finalizeReflex (element, reflex, noop, reflexId) {
// all operations have completed, animation etc is now safe
}
}
14 changes: 14 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.

import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
import StimulusReflex from 'stimulus_reflex'
import consumer from '../channels/consumer'
import controller from '../controllers/application_controller'

const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))
StimulusReflex.initialize(application, { consumer, controller, isolate: true })
StimulusReflex.debug = process.env.RAILS_ENV === 'development'
2 changes: 2 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ import "channels"

Rails.start()
Turbolinks.start()

import "controllers"
3 changes: 3 additions & 0 deletions app/models/aces/inbound_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ def to_event
}
end

def resubmittable?
payload.present? && ['Sent', 'Failed'].include?(result)
end
end
end
6 changes: 3 additions & 3 deletions app/operations/curam/check_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def call(id)

protected

def find_transfer(application_id)
transfers = Aces::Transfer.where(application_identifier: application_id)
transfers.any? ? transfers.last : Failure(:no_transfers_found)
def find_transfer(transfer_id)
transfer = Aces::Transfer.find(transfer_id)
transfer || Failure(:no_transfers_found)
end

def build_check_request(transfer)
Expand Down
12 changes: 12 additions & 0 deletions app/reflexes/application_reflex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class ApplicationReflex < StimulusReflex::Reflex
# Put application-wide Reflex behavior and callbacks in this file.
#
# Example:
#
# # If your ActionCable connection is: `identified_by :current_user`
# delegate :current_user, to: :connection
#
# Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
end
18 changes: 18 additions & 0 deletions app/reflexes/report_reflex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# Update report pages based on user actions
class ReportReflex < ApplicationReflex

def change_date
session_name = element.dataset[:session]
session[session_name] = Date.parse(element.value)
end

def check_payload
Curam::CheckPayload.new.call(element.dataset[:id])
end

def resubmit_to_enroll
Transfers::ToEnroll.new.call(element.dataset[:payload], element.dataset[:id])
end
end
Loading