Commit 27d97774 authored by Greg Gard's avatar Greg Gard

adding labs

parent 8cf73f70
#
# aka labs
#
class DiagnosticProceduresController < ApplicationController
#
def index
@diagnostic_procedures = resource_parent.diagnostic_procedures.kept.order(created_at: 'desc').page params[:page]
end
#
def new
@diagnostic_procedure = resource_parent.diagnostic_procedures.new
end
#
def create
@diagnostic_procedure = resource_parent.diagnostic_procedures.new(resource_params)
@diagnostic_procedure.save!
set_ajax_data(
message: "Diagnostic Procedure created.",
diagnostic_procedure: @diagnostic_procedure.ajax_attributes,
redirect_to: patient_diagnostic_procedures_path(resource_parent)
)
end
def show
rescue *user_errors => er
set_ajax_user_error er, @diagnostic_procedure
rescue => er
set_ajax_stack_error er, @diagnostic_procedure
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 patient_diagnostic_procedures_path(resource_parent), notice: e
rescue => e
log_stack_error e
redirect_to patient_diagnostic_procedures_path(resource_parent), notice: stack_error_message
end
#
def update
@diagnostic_procedure.update! resource_params
set_ajax_data(
message: "Diagnostic Procedure updated.",
diagnostic_procedure: @diagnostic_procedure.ajax_attributes,
redirect_to: patient_diagnostic_procedures_path(resource_parent)
)
rescue *user_errors => er
set_ajax_user_error er, @diagnostic_procedure
rescue => er
set_ajax_stack_error er, @diagnostic_procedure
ensure
render_json
end
# TODO: undiscard
def destroy
@diagnostic_procedure.discard || raise("Unable to delete")
set_ajax_data(
message: "Diagnostic Procedure deleted.",
diagnostic_procedure: @diagnostic_procedure.ajax_attributes,
redirect_to: patient_diagnostic_procedures_path(resource_parent)
)
rescue *user_errors => er
set_ajax_user_error er, @diagnostic_procedure
rescue => er
set_ajax_stack_error er, @diagnostic_procedure
ensure
render_json
end
# **********************
private
def set_resource_parent
self.resource_parent = @patient = Patient.kept.find(params[:patient_id])
end
def set_resource
self.resource = @diagnostic_procedure = resource_parent.diagnostic_procedures.kept.find(params[:id])
end
end
\ No newline at end of file
......@@ -52,7 +52,7 @@ module EMT
_v = m.send("#{v}_before_type_cast").to_s
return !required if _v.blank?
_d = Chronic.parse(_v)
_d = Chronic.parse(_v) # must be a string
block_given? ? yield(_d) : _d
rescue
nil
......
......@@ -12,7 +12,7 @@ class Admission < ApplicationRecord
after_initialize :set_defaults
before_validation do |m|
m.moment = (Chronic.parse(m.moment_before_type_cast) rescue nil)
m.moment = (Chronic.parse(m.moment_before_type_cast.to_s) rescue nil)
end
......
class DiagnosticProcedure < ApplicationRecord
include Discard::Model
def self.params_whitelist
[:patient_id, :description, :moment]
end
# *************************
# validations/callbacks
#
after_initialize :set_defaults
before_validation do |m|
m.moment = (Chronic.parse(m.moment_before_type_cast.to_s) rescue nil)
end
# *****************************
#
validate do |m|
m.errors.add :patient_id, "missing/invalid" unless m.patient_id.to_i > 0
m.errors.add :description, "missing/invalid" unless m.valid_description(m, :description)
m.errors.add :moment, "missing/invalid" unless valid_date(m, :moment)
end
# ***************************
# instance methods
#
belongs_to :patient
def fmt_patient_name
patient&.name || EMT::UKNOWN
end
#
def fmt_moment
moment.fmt(:mdy12)
end
def ajax_attributes
attributes
end
def set_defaults
self.moment ||= Time.now
self.moment ||= Time.now
end
end
\ No newline at end of file
......@@ -16,7 +16,7 @@ class Patient < ApplicationRecord
# validations/callbacks
#
before_validation do |m|
m.dob = (Chronic.parse(m.dob_before_type_cast) rescue nil)
m.dob = (Chronic.parse(m.dob_before_type_cast.to_s) rescue nil)
end
......
......@@ -12,7 +12,7 @@ class Transfer < ApplicationRecord
after_initialize :set_defaults
before_validation do |m|
m.form_sent_at = (Chronic.parse(m.form_sent_at_before_type_cast) rescue nil)
m.form_sent_at = (Chronic.parse(m.form_sent_at_before_type_cast.to_s) rescue nil)
end
validate do |m|
......
<div class='emt-facilities-form'>
<%= form_with model: facility, class: 'emt-form' do |f| %>
<%= emt_form_errors(facility) %>
<div class='emt-diagnostic_procedures-form'>
<%= form_with model: [resource_parent, diagnostic_procedure], class: 'emt-form' do |f| %>
<%= emt_form_errors(diagnostic_procedure) %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :description %>
<%= f.label :description, "Procedure/Lab" %>
<%= f.text_field :description %>
</div>
<%= emt_form_buttons(facility) %>
<div>
<%= f.label :moment, "Ordered Date/Time:" %>
<%= f.text_field :moment, value: diagnostic_procedure.fmt_moment %>
</div>
<%= emt_form_buttons(diagnostic_procedure, resource_parent) %>
<% end %>
</div>
\ No newline at end of file
<div class='emt-patients-edit'>
<%= render 'form', facility: @facility %>
<div class='emt-diagnostic_procedures-edit'>
<%= emt_patient_header resource_parent %>
<%= render 'form', diagnostic_procedure: @diagnostic_procedure %>
</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-diagnostic_procedures'>
<%= emt_patient_header resource_parent %>
<%= link_to "Add Diagnostic Procedure", new_patient_diagnostic_procedure_path(resource_parent), class: 'emt-btn emt-brand' %>
<%= paginate @diagnostic_procedures %>
<table class='emt-table'>
<tr>
<th>Name</th>
<th>Description</th>
<th>Procedure/Lab</th>
<th>Date Ordered</th>
</tr>
<% @facilities.each_with_index do |f, idx| %>
<% @diagnostic_procedures.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_patient_diagnostic_procedure_path(resource_parent, f) %></td>
<td><%= f.fmt_moment %></td>
</tr>
<% end %>
</table>
......
<div class='emt-patients-new'>
<%= render 'form', facility: @facility %>
<div class='emt-diagnostic_procedures-new'>
<%= emt_patient_header resource_parent %>
<%= render 'form', diagnostic_procedure: @diagnostic_procedure %>
</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