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

HMIS ID Validation #289

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
50 changes: 26 additions & 24 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ClientsController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:update]
before_action :set_client, only: %i[show update]

def index
@q = Client.ransack(params[:q])
Expand All @@ -13,32 +14,9 @@ def search
render json: results
end

def show
@client = Client.find(params[:id])
@existing_voucher = @client.current_voucher
@editing = params[:editing]
@hotels = Hotel.all
@hotel_map = Hotel.all.pluck(:id, :name).to_h
@incidents =
@client
.incident_reports
.order(created_at: :desc)
.map do |incident|
{
reportedBy: {
firstName: incident.reporter.first_name,
lastName: incident.reporter.last_name,
email: incident.reporter.email,
},
dateOfIncident: incident.occurred_at,
description: incident.description,
}
end
@incident_report = IncidentReport.new
end
def show; end

def update
@client = Client.find(params[:id])
client_params = params.require(:client).permit!

if client_params['date_of_birth'].blank?
Expand Down Expand Up @@ -93,4 +71,28 @@ def create

render json: client.errors.full_messages, status: :unprocessable_entity
end

def set_client
@client = Client.find(params[:id])
@existing_voucher = @client.current_voucher
@editing = params[:editing]
@hotels = Hotel.all
@hotel_map = Hotel.all.pluck(:id, :name).to_h
@incidents =
@client
.incident_reports
.order(created_at: :desc)
.map do |incident|
{
reportedBy: {
firstName: incident.reporter.first_name,
lastName: incident.reporter.last_name,
email: incident.reporter.email,
},
dateOfIncident: incident.occurred_at,
description: incident.description,
}
end
@incident_report = IncidentReport.new
end
end
44 changes: 20 additions & 24 deletions app/controllers/intakes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ class IntakesController < ApplicationController
def new
@client =
params[:client_id].present? ? Client.find(params[:client_id]) : Client.new

@intake = Intake.new
@voucher = Voucher.new
end

def create
# reject me if client hasn't agreed to waiver and participant agreement form
client_params = intake_params[:client_attributes]

@client =
Expand All @@ -34,34 +32,15 @@ def create
force_intake: false,
),
)

return render :new if [email protected]

if profile_photo_data_url.present?
# The data is Base64 and coming from the camera.
# Use that data to create a file for active storage.
# data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD....
blob =
ActiveStorage::Blob.create_after_upload!(
io:
StringIO.new(
(Base64.decode64(profile_photo_data_url.split(',')[1] || '')),
),
filename: 'profile_photo.jpeg',
content_type: 'image/jpeg',
)

@client.profile_photo.attach(blob)
end

@intake =
Intake.new(
intake_params
.except(:camera, :voucher, :client_attributes)
.merge(
swap_id: @swap.id,
user_id: current_user.id,
client_id: @client.id,
# client_id: @client.id,
client: @client,
household_tanf: !!intake_params[:household_tanf],
have_you_ever_experienced_homelessness_before:
!intake_params[:homelessness_first_time],
Expand All @@ -80,7 +59,24 @@ def create
),
)

return render :new if [email protected]
if profile_photo_data_url.present?
# The data is Base64 and coming from the camera.
# Use that data to create a file for active storage.
# data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD....
blob =
ActiveStorage::Blob.create_after_upload!(
io:
StringIO.new(
(Base64.decode64(profile_photo_data_url.split(',')[1] || '')),
),
filename: 'profile_photo.jpeg',
content_type: 'image/jpeg',
)

@client.profile_photo.attach(blob)
end

return render :new if ([email protected] || [email protected])

redirect_to new_voucher_path(
client_id: @client.id,
Expand Down
9 changes: 9 additions & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class Client < ApplicationRecord
validates :first_name, :last_name, :date_of_birth, presence: true
validates :gender, inclusion: { in: Client::GENDER, allow_nil: true }
validates :ethnicity, inclusion: { in: Client::ETHNICITY, allow_nil: true }
validates :hmis_id,
uniqueness: true,
allow_nil: true,
length: {
is: 9,
},
format: {
with: /[A-Za-z0-9]+/,
}

# validate :accepted_race_values
# validates :phone_number, phone: { possible: true, allow_nil: true }
Expand Down
10 changes: 10 additions & 0 deletions app/views/clients/_client_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
</div>
<div class="rounded-lg bg-white shadow">
<div class="bg-white p-4 rounded-t-lg border border-gray-200">
<% if @client.errors.any? %>
<div id="error_explanation" class="my-4 md:my-12 p-8 bg-red-400 font-bold">
<p><%= pluralize(@client.errors.count, "error") %> prohibited this client from being saved:</p>
<ul class="mt-8">
<% @client.errors.full_messages.each do |message| %>
<li class=""><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<div>
Expand Down