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

[WIP] Partner::AGENCY_TYPES is an enum on Partners::Profile #4254

Open
wants to merge 4 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
41 changes: 0 additions & 41 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,6 @@ class Partner < ApplicationRecord
where(status: status.to_sym)
}

AGENCY_TYPES = {
"CAREER" => "Career technical training",
"ABUSE" => "Child abuse resource center",
"CHURCH" => "Church outreach ministry",
"COLLEGE" => "College and Universities",
"CDC" => "Community development corporation",
"HEALTH" => "Community health program or clinic",
"OUTREACH" => "Community outreach services",
"LEGAL" => "Correctional Facilities / Jail / Prison / Legal System",
"CRISIS" => "Crisis/Disaster services",
"DISAB" => "Developmental disabilities program",
"DOMV" => "Domestic violence shelter",
"ECE" => "Early Childhood Education/Childcare",
"CHILD" => "Early childhood services",
"EDU" => "Education program",
"FAMILY" => "Family resource center",
"FOOD" => "Food bank/pantry",
"FOSTER" => "Foster Program",
"GOVT" => "Government Agency/Affiliate",
"HEADSTART" => "Head Start/Early Head Start",
"HOMEVISIT" => "Home visits",
"HOMELESS" => "Homeless resource center",
"HOSP" => "Hospital",
"INFPAN" => "Infant/Child Pantry/Closet",
"LIB" => "Library",
"MILITARY" => "Military Bases/Veteran Services",
"POLICE" => "Police Station",
"PREG" => "Pregnancy resource center",
"PRESCH" => "Preschool",
"REF" => "Refugee resource center",
"ES" => "School - Elementary School",
"HS" => "School - High School",
"MS" => "School - Middle School",
"SENIOR" => "Senior Center",
"TRIBAL" => "Tribal/Native-Based Organization",
"TREAT" => "Treatment clinic",
"2YCOLLEGE" => "Two-Year College",
"WIC" => "Women, Infants and Children",
"OTHER" => "Other"
}.freeze

ALL_PARTIALS = %w[
media_information
agency_stability
Expand Down
47 changes: 47 additions & 0 deletions app/models/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,49 @@ class Profile < Base
validate :client_share_is_0_or_100
validate :has_at_least_one_request_setting

AGENCY_TYPES = {
"career" => "Career technical training",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might not be what you had in mind? The keys for enum are the strings we're going to use to access it, but the values are what is stored in the database. We don't want these big strings stored in the database. I would have expected an enum that looks something like this

enum :agency_type, %w(career abuse church college ...).to_h { |s| [s, s] }

AGENCY_TYPE_LABELS = {
  "career" => "Career technical training",
  "abuse" => "Child abuse resource center",
   ...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to move the big strings out of the database, we (the core team) will need to check whether there is anything in the db that does not match up to the current list. Just because it's been a long time and there may have been earlier adjustments. If so, the migration might have to be a little more sophisticated, yes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...there are tons of agency types that aren't in this list. Yeah we'll need to decide what to do with them.

501 C 3 Non Profit: 1
501c3: 1
ASO: 1
Basic Needs: 1
Career technical training: 28
Case Management: 1
Charitable Non Profit 501C3: 1
Child Advocacy Center: 1
Child Care Center: 1
Child Placing Agency: 1
Child abuse resource center: 16
Children and Family Services : 1
Church: 2
Church : 1
Church food pantry: 1
Church ministry: 1
Church outreach ministry: 122
Clothing, closet for children birth to age 7: 1
Community Ministry: 1
Community Service Organization: 1
Community development corporation: 77
Community health program: 87
Community health program or clinic: 2
Community outreach services: 181
Correctional Facilities / Jail / Prison / Legal System: 1
Crisis/Disaster services: 5
Developmental disabilities program: 9
Diaper Bank: 1
Diaper agency: 1
Domestic Violence/Non-Profit: 1
Domestic violence shelter: 27
Early childhood services: 88
Education: 1
Education program: 229
Educational: 1
Emergency Crisis/Human Trafficking/Refuee Service: 1
Family resource center: 91
Food Pantry: 5
Food Pantry - Emergency Diaper Distribution: 1
Food bank: 1
Food bank/pantry: 174
Food pantry: 1
Foster Care: 1
Government Agency/Affiliate: 65
Head Start/Early Head Start: 45
Home visits: 56
Homeless resource center: 54
Hospital : 1
Human Services: 1
Infant/Child Pantry/Closet: 20
Law Enforcement Agency: 1
Maternity Home: 1
Mental Health: 1
NON PROFIT: 1
Non Profit: 2
Non-Profit: 5
Non-Profit - Education: 1
Non-Profit Victim Services and Family Resource Center: 1
Non-Profit. Clothing, Food and Diaper Assistance: 1
Nonprofit: 1
Nonprofit preschool: 1
Nonprofit/School: 1
Not for Profit: 1
Other: 347
PAT Program: 1
Perinatal Mental Health Peer Support: 1
Pregnancy Center - Charitable Health : 1
Pregnancy Resource Center: 1
Pregnancy resource center: 37
Primary Care Doctor: 1
Public Health: 1
Public School: 1
Refugee resource center: 12
Reproductive Health Care, Maternity Services: 1
Safety Net Organization: 1
School: 2
School - High School: 3
School - Middle School: 3
School District: 2
School District : 1
Treatment clinic: 25
Vocational training program : 1
Women Substance Abuse: 1
Women, Infants and Children: 59
Youth Services: 1
charitable organization: 1
non profit: 2
non-profit: 2
nonprofit : 1
public elementary school : 1
test: 1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I'm silly. All we have to do is move those non-standard names to "other_agency_type" and set "agency_type" to "Other".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so loop through each profile, see if its current agency_type is in the approved list, and if not, do the swap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - most of those are a close match to one of the types. I wonder if it was initially just implemented as a text field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll work on this on Monday.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that some of those will just be a difference in capitalization or spacing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll make a separate data migration PR to clean up the non-standard agency types, and then I'll write a SQL migration in this PR that converts from standard long-form agency type to agency type enum.

It'll be a clearer separation of concerns and we won't have two places to consider if something goes wrong.

"abuse" => "Child abuse resource center",
"church" => "Church outreach ministry",
"college" => "College and Universities",
"cdc" => "Community development corporation",
"health" => "Community health program or clinic",
"outreach" => "Community outreach services",
"legal" => "Correctional Facilities / Jail / Prison / Legal System",
"crisis" => "Crisis/Disaster services",
"disab" => "Developmental disabilities program",
"domv" => "Domestic violence shelter",
"ece" => "Early Childhood Education/Childcare",
"child" => "Early childhood services",
"edu" => "Education program",
"family" => "Family resource center",
"food" => "Food bank/pantry",
"foster" => "Foster Program",
"govt" => "Government Agency/Affiliate",
"headstart" => "Head Start/Early Head Start",
"homevisit" => "Home visits",
"homeless" => "Homeless resource center",
"hosp" => "Hospital",
"infpan" => "Infant/Child Pantry/Closet",
"lib" => "Library",
"military" => "Military Bases/Veteran Services",
"police" => "Police Station",
"preg" => "Pregnancy resource center",
"presch" => "Preschool",
"ref" => "Refugee resource center",
"es" => "School - Elementary School",
"hs" => "School - High School",
"ms" => "School - Middle School",
"senior" => "Senior Center",
"tribal" => "Tribal/Native-Based Organization",
"treat" => "Treatment clinic",
"2ycollege" => "Two-Year College",
"wic" => "Women, Infants and Children",
"other" => "Other"
}

enum :agency_type, AGENCY_TYPES.to_h { |s, _| [s, s] }, prefix: "agency_type"

self.ignored_columns = %w[
evidence_based_description
program_client_improvement
Expand All @@ -113,6 +156,10 @@ class Profile < Base
ages_served
]

def agency_type_description
AGENCY_TYPES[agency_type]
end

def client_share_total
# client_share could be nil
served_areas.map(&:client_share).compact.sum
Expand Down
2 changes: 1 addition & 1 deletion app/services/reports/partner_info_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def partner_agencies
end

def partner_agency_counts
partner_agency_profiles.map(&:agency_type).tally
partner_agency_profiles.map(&:agency_type_description).tally
end

def partner_zipcodes_serviced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div class="card-body">
<%= form.input :name, label: "Agency Name", class: "form-control", wrapper: :input_group %>
<%= profile_form.input :agency_type, collection: Partner::AGENCY_TYPES.values, label: "Agency Type", class: "form-control", wrapper: :input_group %>
<%= profile_form.input :agency_type, collection: Partners::Profile.agency_types, label: "Agency Type", class: "form-control", wrapper: :input_group %>
<%= profile_form.input :other_agency_type, label: "Other Agency Type", class: "form-control", wrapper: :input_group %>
<div class="form-group row">
<label class="control-label col-md-3">501(c)(3) IRS Determination Letter</label>
Expand Down
4 changes: 2 additions & 2 deletions app/views/partners/profiles/show/_agency_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<dd><%= profile.partner.name %></dd>

<dt>Agency Type</dt>
<dd><%= profile.agency_type %></dd>
<dd><%= profile.agency_type_description %></dd>

<% if profile.agency_type == "Other" %>
<% if profile.agency_type_other? %>
<dt>Other Agency Type</dt>
<dd><%= profile.other_agency_type %></dd>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/profiles/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<%# The field for inputting the name registers it as partner.name, %>
<%# not partner_profile.name, so this pulls from partner.name %>
<p>Name: <%= @partner.name %></p>
<p>Agency Type: <%= partner_profile.agency_type %>
<% if partner_profile.agency_type == "Other" && partner_profile.other_agency_type %>
<p>Agency Type: <%= partner_profile.agency_type_description %>
<% if partner_profile.agency_type_other? && partner_profile.other_agency_type %>
(<%= partner_profile.other_agency_type %>)
<% end %>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ConvertPartnerProfileAgencyTypesToEnums < ActiveRecord::Migration[7.0]
def up
Partners::Profile::AGENCY_TYPES.each do |enum, desc|
ActiveRecord::Base.connection.execute <<-SQL
UPDATE partner_profiles
SET agency_type = '#{enum}'
WHERE agency_type = '#{desc}'
SQL
end
end

def down
Partners::Profile::AGENCY_TYPES.each do |enum, desc|
ActiveRecord::Base.connection.execute <<-SQL
UPDATE partner_profiles
SET agency_type = '#{desc}'
WHERE agency_type = '#{enum}'
SQL
end
end
end
1 change: 1 addition & 0 deletions spec/factories/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :partner_profile, class: Partners::Profile do
partner { Partner.first || create(:partner) }
essentials_bank_id { Organization.try(:first).id || create(:organization).id }
agency_type { "outreach" }
website { "http://some-site.org" }
primary_contact_email { Faker::Internet.email }
primary_contact_name { Faker::Name.name }
Expand Down
6 changes: 3 additions & 3 deletions spec/services/reports/partner_info_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

it 'should report normal values' do
p1 = create(:partner, :uninvited, organization: organization, name: 'Partner 1')
p1.profile.update!(zips_served: '90210-1234', agency_type: Partner::AGENCY_TYPES['CAREER'])
p1.profile.update!(zips_served: '90210-1234', agency_type: 'career')
p2 = create(:partner, :uninvited, organization: organization, name: 'Partner 2')
p2.profile.update!(zips_served: '12345', agency_type: Partner::AGENCY_TYPES['CAREER'])
p2.profile.update!(zips_served: '12345', agency_type: 'career')
p3 = create(:partner, :uninvited, organization: organization, name: 'Partner 3')
p3.profile.update!(zips_served: '09876-3564', agency_type: Partner::AGENCY_TYPES['EDU'])
p3.profile.update!(zips_served: '09876-3564', agency_type: 'edu')

expect(report.report).to eq({
entries: { "Agency Type: Career technical training" => 2,
Expand Down