Commit 285c2cec authored by Greg Gard's avatar Greg Gard

adding dropdowns for patients, facilities etc

parent b76e2dff
......@@ -7,11 +7,12 @@ class FacilitiesController < ApplicationController
#
def new
@facility = Facility.new
end
#
def create
@facility = Facility.new(resource_params)
@facility.save!
set_ajax_data(
message: "Facility created.",
......@@ -75,5 +76,13 @@ class FacilitiesController < ApplicationController
ensure
render_json
end
# ************************
private
def set_resource
self.resource = @facility = Facility.kept.find(params[:id])
end
end
\ No newline at end of file
class Facility < ApplicationRecord
include Discard::Model
def self.select_options
kept.all.map{|p| [p.name, p.id]}
end
def self.params_whitelist
[:name, :description]
......
......@@ -7,6 +7,10 @@ class Patient < ApplicationRecord
genders.map{|k, v| [k.to_s.capitalize, k]}
end
def self.select_options
kept.all.map{|p| [p.name, p.id]}
end
# TODO: make mr auto-assigned? if so then disallow mass assign, admins only on renaming?
def self.params_whitelist
[:mr, :first_name, :middle_name, :last_name, :dob, :gender]
......@@ -24,8 +28,7 @@ class Patient < ApplicationRecord
m.errors.add :first_name, "missing/invalid" unless valid_person_name_part(m, :first_name)
m.errors.add :middle_name, "invalid" unless valid_person_name_part(m, :middle_name, required: false)
m.errors.add :dob, "invalid" unless valid_dob(m, :dob, required: false)
m.errors.add :unit, "missing/invalid" unless m.class.units.keys.include?(m.unit)
m.errors.add :gender, "missing/invalid" unless m.gender.presence && m.class.gender.keys.include?(m.gender)
m.errors.add :gender, "missing/invalid" unless m.gender.presence && m.class.genders.keys.include?(m.gender)
end
......
......@@ -2,16 +2,17 @@
<%= form_with model: admission, class: 'emt-form' do |f| %>
<%= emt_form_errors(admission) %>
<div>
<%= f.label :patient_id, "Patient" %>
<%= f.text_field :patient_id %>
<%= f.select :patient_id, Patient.select_options, include_blank: 'Select patient' %>
</div>
<div>
<%= f.label :facility_id, "Referring Facility" %>
<%= f.text_field :facility_id %>
<%= f.select :facility_id, Facility.select_options, include_blank: 'Select facility' %>
</div>
<div>
<%= f.label :moment, "Referred on Date/Time:" %>
<%= f.text_field :moment, value: admission.fmt_moment %>
......
......@@ -28,7 +28,7 @@
<div>
<%= f.label :gender, "Sex" %>
<%= f.select :gender, patient.class.gender_options, prompt: 'Select gender' %>
<%= f.select :gender, patient.class.gender_options, include_blank: 'Select gender' %>
</div>
<%= emt_form_buttons(patient) %>
......
......@@ -4,14 +4,14 @@
<div>
<%= f.label :patient_id, "Patient" %>
<%= f.text_field :patient_id %>
<%= f.select :patient_id, Patient.select_options, include_blank: 'Select patient' %>
</div>
<div>
<%= f.label :facility_id, "Referring Facility" %>
<%= f.text_field :facility_id %>
<%= f.select :facility_id, Facility.select_options, include_blank: 'Select facility' %>
</div>
<div>
<%= f.label :form_sent_at, "Form sent Date/Time:" %>
<%= f.text_field :form_sent_at, value: transfer.fmt_form_sent_at %>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment