Dear all
Please see the following module, In module SX3 SX4 and SX5 have similar
class Tasklist, but inherit from different class.
I will use the following code to connect to different data sources
RemoteSX3Model.establish_connection sx3_hash
RemoteSX4Model.establish_connection sx4_hash
RemoteSX5Model.establish_connection sx5_hash
How can I refactor my code in module to look simpler? Thank you very
much
class RemoteSX3Model < ActiveRecord::Base
def readonly?
true
end
end
class RemoteSX4Model < ActiveRecord::Base
def readonly?
true
end
end
class RemoteSX5Model < ActiveRecord::Base
def readonly?
true
end
end
module SX3
class Request < RemoteSX3Model
set_table_name “request”
set_primary_key “req_reqno”
has_many :print_audit, :class_name => “PrintAudit”, :foreign_key =>
“prtaud_reqno”
has_many :request_copy_hist, :class_name => “RequestCopyHist”,
:foreign_key => “reqcp_reqno”
belongs_to :patient, :class_name => “SX9::Patient”, :foreign_key =>
“pat_encounter_group”
end
class RequestCopyHist < RemoteSX3Model
set_table_name “request_copy_hist”
belongs_to :request, :class_name => “Request”, :foreign_key =>
“reqcp_reqno”
end
class Tasklist < RemoteSX3Model
set_table_name “lisg_tasklist”
def self.find_incompete_tasklist
find(:all, :conditions => ["g_status in (0,10,98) and
g_request_time between ? and ?", 1.day.ago, 30.minute.ago])
end
end
end
module SX4
class Tasklist < RemoteSX4Model
set_table_name “lisg_tasklist”
def self.find_incompete_tasklist
find(:all, :conditions => ["g_status in (0,10,98) and
g_request_time between ? and ?", 1.day.ago, 30.minute.ago])
end
end
end
module SX5
class Tasklist < RemoteSX5Model
set_table_name “lisg_tasklist”
def self.find_incompete_tasklist
find(:all, :conditions => ["g_status in (0,10,98) and
g_request_time between ? and ?", 1.day.ago, 30.minute.ago])
end
end
end