Created
May 14, 2015 21:27
-
-
Save anonymous/51888d5fcc8406a6deb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Instance < ActiveRecord::Base | |
has_many :reports | |
has_many :exams, primary_key: 'study_instance_uid', foreign_key: 'study_inst_uid', inverse_of: :instance | |
has_many :patients, through: :exams | |
before_save :set_reading_physician, if: :should_set_reading_physician? | |
def reading_physician | |
(set_reading_physician and save!) if should_set_reading_physician? | |
read_attribute(:reading_physician) || '' | |
end | |
private | |
def should_set_reading_physician? | |
( | |
v = read_attribute :reading_physician | |
v.nil? | |
) && patient | |
end | |
def set_reading_physician | |
self.reading_physician = patient.reading_physician | |
end | |
end |
smathy
commented
May 14, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment