Commit b76e2dff authored by Greg Gard's avatar Greg Gard

adding symptoms

parent 78ec082b
class SymptomsController < ApplicationController
#
def index
@symptoms = resource_parent.symptoms.kept.order(created_at: 'desc').page params[:page]
end
#
def new
@symptom = resource_parent.symptoms.new
end
#
def create
@symptom = resource_parent.symptoms.new(resource_params)
@symptom.save!
set_ajax_data(
message: "Symptom created.",
symptom: @symptom.ajax_attributes,
redirect_to: admission_symptoms_path(resource_parent)
)
end
def show
rescue *user_errors => er
set_ajax_user_error er, @symptom
rescue => er
set_ajax_stack_error er, @symptom
ensure
render_json
end
#
def show
redirect_to resource_parent, notice: "That view isn't implemented."
end
#
def edit
rescue *user_errors => e
redirect_to admission_symptoms_path(resource_parent), notice: e
rescue => e
log_stack_error e
redirect_to admission_symptoms_path(resource_parent), notice: stack_error_message
end
#
def update
@symptom.update! resource_params
set_ajax_data(
message: "Symptom updated.",
symptom: @symptom.ajax_attributes,
redirect_to: admission_symptoms_path(resource_parent)
)
rescue *user_errors => er
set_ajax_user_error er, @symptom
rescue => er
set_ajax_stack_error er, @symptom
ensure
render_json
end
# TODO: undiscard
def destroy
@symptom.discard || raise("Unable to delete")
set_ajax_data(
message: "Symptom deleted.",
symptom: @symptom.ajax_attributes,
redirect_to: admission_symptoms_path(resource_parent)
)
rescue *user_errors => er
set_ajax_user_error er, @symptom
rescue => er
set_ajax_stack_error er, @symptom
ensure
render_json
end
# **********************
private
def set_resource_parent
self.resource_parent = @admission = Admission.kept.find(params[:admission_id])
end
def set_resource
self.resource = @symptom = resource_parent.symptoms.kept.find(params[:id])
end
end
\ No newline at end of file
......@@ -150,7 +150,8 @@ module ApplicationHelper
{label: "Patients", url: admission_patients_path(resource.id)},
{label: "Transfers", url: admission_transfers_path(resource.id)},
{label: "Diagnoses", url: admission_diagnoses_path(resource.id)},
{label: "Observations", url: admission_observations_path(resource.id)}
{label: "Observations", url: admission_observations_path(resource.id)},
{label: "Symptoms", url: admission_symptoms_path(resource.id)}
]
end
......
class Symptom < ApplicationRecord
include Discard::Model
def self.params_whitelist
[:admission_id, :description]
end
# *************************
# validations/callbacks
#
after_initialize :set_defaults
before_validation do |m|
end
validate do |m|
m.errors.add :admission_id, "missing/invalid" unless m.admission_id.to_i > 0
m.errors.add :description, "missing/invalid" unless valid_description(m, :description)
end
# ***************************
# instance methods
#
belongs_to :admission
#
def fmt_created_at
created_at.fmt(:mdy12)
end
def ajax_attributes
attributes
end
def set_defaults
end
end
\ No newline at end of file
<div class='emt-facilities-form'>
<%= form_with model: facility, class: 'emt-form' do |f| %>
<%= emt_form_errors(facility) %>
<div class='emt-symptoms-form'>
<%= form_with model: [resource_parent, symptom], class: 'emt-form' do |f| %>
<%= emt_form_errors(symptom) %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :description %>
<%= f.text_field :description %>
</div>
<%= emt_form_buttons(facility) %>
<%= emt_form_buttons(symptom, resource_parent) %>
<% end %>
</div>
\ No newline at end of file
<div class='emt-patients-edit'>
<%= render 'form', facility: @facility %>
<div class='emt-symptoms-new'>
<%= emt_admission_header resource_parent %>
<%= render 'form', symptom: @symptom %>
</div>
\ No newline at end of file
<div class='emt-facilities'>
<%= link_to "Add Facility", new_facility_path, class: 'emt-btn emt-brand' %>
<%= paginate @facilities %>
<div class='emt-symptoms'>
<%= emt_admission_header resource_parent %>
<%= link_to "Add Symptom", new_admission_symptom_path(resource_parent), class: 'emt-btn emt-brand' %>
<%= paginate @symptoms %>
<table class='emt-table'>
<tr>
<th>Name</th>
<th>Description</th>
<th>Date Entered</th>
</tr>
<% @facilities.each_with_index do |f, idx| %>
<% @symptoms.each_with_index do |f, idx| %>
<tr>
<td><%= link_to f.name, edit_facility_path(f) %></td>
<td><%= f.description %></td>
<td><%= link_to f.description, edit_admission_symptom_path(resource_parent, f) %></td>
<td><%= f.fmt_created_at %></td>
</tr>
<% end %>
</table>
......
<div class='emt-patients-new'>
<%= render 'form', facility: @facility %>
<div class='emt-symptoms-new'>
<%= emt_admission_header resource_parent %>
<%= render 'form', symptom: @symptom %>
</div>
\ No newline at end of file
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