Class: CandidateControl

Inherits:
ActiveRecordShared show all
Defined in:
app/models/candidate_control.rb

Instance Method Summary collapse

Instance Method Details

#create_study_subjects(case_subject, grouping = '6') ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/candidate_control.rb', line 39

def create_study_subjects(case_subject,grouping = '6')
	next_orderno = case_subject.next_control_orderno(grouping)

	CandidateControl.transaction do

		#	Use a block so can assign all attributes without concern for attr_protected
		child = StudySubject.new do |s|
			s.subject_type = SubjectType['Control']
			s.vital_status = VitalStatus['living']
			s.sex                   = sex
			s.mom_is_biomom         = mom_is_biomom
			s.dad_is_biodad         = dad_is_biodad
			s.mother_hispanicity_id = mother_hispanicity_id
			s.father_hispanicity_id = father_hispanicity_id
			s.birth_type            = birth_type
			s.mother_yrs_educ       = mother_yrs_educ
			s.father_yrs_educ       = father_yrs_educ
			s.birth_county          = birth_county
			s.hispanicity_id        = ( 
				( [mother_hispanicity_id,father_hispanicity_id].include?(1) ) ? 1 : nil )
			s.first_name         = first_name
			s.middle_name        = middle_name
			s.last_name          = last_name
			s.dob                = dob
			s.mother_first_name  = mother_first_name
			s.mother_middle_name = mother_middle_name
			s.mother_last_name   = mother_last_name
			s.mother_maiden_name = mother_maiden_name
			s.mother_race_id     = mother_race_id
			s.father_race_id     = father_race_id

			s.case_control_type  = grouping
			s.state_registrar_no = state_registrar_no
			s.local_registrar_no = local_registrar_no
			s.orderno            = next_orderno
			s.matchingid         = case_subject.subjectid
			s.patid              = case_subject.patid
			s.is_matched         = true
		end
		child.save!
		child.assign_icf_master_id


#	TODO May have to set is_matched for both the Case and Control here [#217]
#	We will default it to null and add logic to set it to true for both the new control and their related case when a new control is added to study_subjects from candidate_controls.
		case_subject.update_attributes!(:is_matched => true)


		#	NOTE this may require passing info
		#	that is in the candidate_control record, but not in the child subject
		#		mother_hispanicity_id	(actually this is now)
		#	worst case scenario is just create the full mother here
		#	rather than through the child.
		child.create_mother	#	({ .... })

		self.study_subject_id = child.id
		self.assigned_on = Date.today
		self.save!
	end
	self
end

#full_nameObject

Returns string containing candidates’s first, middle and last name



30
31
32
# File 'app/models/candidate_control.rb', line 30

def full_name
	[first_name, middle_name, last_name].delete_if(&:blank?).join(' ')
end

#mother_full_nameObject

Returns string containing candidates’s mother’s first, middle and last name



35
36
37
# File 'app/models/candidate_control.rb', line 35

def mother_full_name
	[mother_first_name, mother_middle_name, mother_last_name].delete_if(&:blank?).join(' ')
end