Patient Model:
Code:
class Patient < ActiveRecord::Base
validates_presence_of :first_name, :last_name, :gender, :date_of_birth, :height, :weight, :prognosis
attr_accessor :first_name, :last_name, :gender,
:address1, :address2, :city, :state, :zip_code,
:date_of_birth, :height, :weight,
:prognosis, :status
PROGNOSIS_TYPES = [
# Displayed # Stored in DB
['Good', 'Good'],
['Fair', 'Fair'],
['Poor', 'Poor']
]
GENDER_TYPES = [
# Displayed # Stored in DB
['Male', 'Male'],
['Female', 'Female']
]
end
Here is the form view:
Code:
<%= error_messages_for :patient %>
<h1>Enter Patient Information</h1>
<div id="patient-form-right">
<% form_for :patient, :url => {:action => :add_patient_info} do |f| %>
<fieldset><legend>Patient Information</legend>
<p><label for="first_name">First Name *</label><br/>
<%= f.text_field :first_name, :size => 30, :maxlength => 60 %>
</p>
<p><label for="last_name">Last Name *</label><br/>
<%= f.text_field :last_name, :size => 30, :maxlength => 60 %>
</p>
<p><label for="address1">Address</label><br/>
<%= f.text_field :address1, :size => 30, :maxlength => 100 %><br/>
<%= f.text_field :address2, :size => 30, :maxlength => 100 %>
</p>
<p><label for="city">City / State / Zip Code</label><br/>
<%= f.text_field :city, :size => 20, :maxlength => 60 %>
<%= f.text_field :state, :size => 2, :maxlength => 2 %>
<%= f.text_field :zip_code, :size => 5, :maxlength => 5 %>
</p>
<p><label for="gender">Gender *</label><br/>
<%= f.select :gender, Patient::GENDER_TYPES, :prompt => 'Select a gender' %>
</p>
<p><label for="date_of_birth">Date of Birth *</label><br/>
<%= f.text_field :date_of_birth, :size => 10, :maxlength => 10 %> (mm/dd/yyyy)
</p>
<p><label for="height">Height *</label><br/>
<%= f.text_field :height, :size => 3, :maxlength => 3 %> inches
</p>
<p><label for="weight">Weight *</label><br/>
<%= f.text_field :weight, :size => 4, :maxlength => 4 %> lbs
</p>
<p><label for="prognosis">Prognosis *</label><br/>
<%= f.select :prognosis, Patient::PROGNOSIS_TYPES, :prompt => 'Select a prognosis' %>
</p>
</fieldset>
</div>
<p><%= submit_tag 'Next Step', :class => 'submit' %></p>
<% end %>
</div>
This is my migration file:
Code:
class CreatePatients < ActiveRecord::Migration
def self.up
create_table :patients do |t|
t.column :first_name, :string, :limit => 60, :null => false
t.column :last_name, :string, :limit => 60, :null => false
t.column :gender, :string, :limit => 10, :null => false
t.column :address1, :string, :limit => 100, :null => true
t.column :address2, :string, :limit => 100, :null => true
t.column :city, :string, :limit => 100, :null => true
t.column :state, :string, :limit => 2, :null => true
t.column :zip_code, :string, :limit => 5, :null => true
t.column :date_of_birth, :date, :null => false
t.column :height, :integer, :null => false
t.column :weight, :integer, :null => false
t.column :prognosis, :string, :limit => 32, :null => false
t.column :status, :string, :limit => 32, :null => false, :default => 'NOT ACTIVE'
end
end
def self.down
drop_table :patients
end
end
Bookmarks