ccls-ccls_engine 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. data/README.rdoc +182 -0
  2. data/app/models/abstract.rb +181 -0
  3. data/app/models/abstract_search.rb +50 -0
  4. data/app/models/abstract_validations.rb +324 -0
  5. data/app/models/address.rb +70 -0
  6. data/app/models/address_type.rb +15 -0
  7. data/app/models/addressing.rb +147 -0
  8. data/app/models/aliquot.rb +44 -0
  9. data/app/models/aliquot_sample_format.rb +13 -0
  10. data/app/models/analysis.rb +14 -0
  11. data/app/models/bc_request.rb +20 -0
  12. data/app/models/candidate_control.rb +101 -0
  13. data/app/models/context.rb +23 -0
  14. data/app/models/context_data_source.rb +4 -0
  15. data/app/models/county.rb +16 -0
  16. data/app/models/data_source.rb +24 -0
  17. data/app/models/diagnosis.rb +23 -0
  18. data/app/models/document_type.rb +16 -0
  19. data/app/models/document_version.rb +27 -0
  20. data/app/models/enrollment.rb +78 -0
  21. data/app/models/enrollment_validations.rb +167 -0
  22. data/app/models/follow_up.rb +16 -0
  23. data/app/models/follow_up_type.rb +18 -0
  24. data/app/models/gift_card.rb +22 -0
  25. data/app/models/gift_card_search.rb +137 -0
  26. data/app/models/home_exposure_response.rb +24 -0
  27. data/app/models/homex_outcome.rb +75 -0
  28. data/app/models/hospital.rb +22 -0
  29. data/app/models/icf_master_id.rb +30 -0
  30. data/app/models/icf_master_tracker.rb +217 -0
  31. data/app/models/icf_master_tracker_change.rb +9 -0
  32. data/app/models/icf_master_tracker_update.rb +50 -0
  33. data/app/models/ineligible_reason.rb +26 -0
  34. data/app/models/instrument.rb +26 -0
  35. data/app/models/instrument_type.rb +17 -0
  36. data/app/models/instrument_version.rb +28 -0
  37. data/app/models/interview.rb +122 -0
  38. data/app/models/interview_method.rb +17 -0
  39. data/app/models/interview_outcome.rb +16 -0
  40. data/app/models/language.rb +28 -0
  41. data/app/models/live_birth_data_update.rb +142 -0
  42. data/app/models/operational_event.rb +99 -0
  43. data/app/models/operational_event_type.rb +31 -0
  44. data/app/models/organization.rb +28 -0
  45. data/app/models/patient.rb +63 -0
  46. data/app/models/patient_validations.rb +118 -0
  47. data/app/models/person.rb +28 -0
  48. data/app/models/phone_number.rb +105 -0
  49. data/app/models/phone_type.rb +15 -0
  50. data/app/models/project.rb +39 -0
  51. data/app/models/project_outcome.rb +19 -0
  52. data/app/models/race.rb +31 -0
  53. data/app/models/refusal_reason.rb +23 -0
  54. data/app/models/sample.rb +168 -0
  55. data/app/models/sample_kit.rb +14 -0
  56. data/app/models/sample_outcome.rb +16 -0
  57. data/app/models/sample_temperature.rb +14 -0
  58. data/app/models/sample_type.rb +37 -0
  59. data/app/models/search.rb +195 -0
  60. data/app/models/section.rb +18 -0
  61. data/app/models/state.rb +25 -0
  62. data/app/models/study_subject.rb +237 -0
  63. data/app/models/study_subject_abstracts.rb +47 -0
  64. data/app/models/study_subject_addresses.rb +34 -0
  65. data/app/models/study_subject_associations.rb +38 -0
  66. data/app/models/study_subject_duplicates.rb +111 -0
  67. data/app/models/study_subject_enrollments.rb +17 -0
  68. data/app/models/study_subject_homex_outcome.rb +22 -0
  69. data/app/models/study_subject_identifier.rb +153 -0
  70. data/app/models/study_subject_interviews.rb +25 -0
  71. data/app/models/study_subject_languages.rb +21 -0
  72. data/app/models/study_subject_operational_events.rb +66 -0
  73. data/app/models/study_subject_patient.rb +177 -0
  74. data/app/models/study_subject_pii.rb +74 -0
  75. data/app/models/study_subject_races.rb +25 -0
  76. data/app/models/study_subject_search.rb +260 -0
  77. data/app/models/study_subject_validations.rb +116 -0
  78. data/app/models/subject_language.rb +11 -0
  79. data/app/models/subject_race.rb +11 -0
  80. data/app/models/subject_relationship.rb +21 -0
  81. data/app/models/subject_type.rb +22 -0
  82. data/app/models/tracing_status.rb +20 -0
  83. data/app/models/transfer.rb +40 -0
  84. data/app/models/unit.rb +14 -0
  85. data/app/models/vital_status.rb +19 -0
  86. data/app/models/zip_code.rb +36 -0
  87. data/config/abstract_fields.yml +1038 -0
  88. data/config/abstract_sections.yml +77 -0
  89. data/config/home_exposure_response_fields.yml +583 -0
  90. data/config/icf_master_tracker_update.yml +56 -0
  91. data/config/live_birth_data_update.yml +56 -0
  92. data/config/shared_use_db.yml +4 -0
  93. data/generators/ccls_engine/USAGE +2 -0
  94. data/generators/ccls_engine/ccls_engine_generator.rb +123 -0
  95. data/generators/ccls_engine/templates/autotest_ccls_engine.rb +3 -0
  96. data/generators/ccls_engine/templates/ccls_engine.rake +12 -0
  97. data/generators/ccls_engine/templates/fixtures/address_types.yml +30 -0
  98. data/generators/ccls_engine/templates/fixtures/context_data_sources.yml +54 -0
  99. data/generators/ccls_engine/templates/fixtures/contexts.yml +19 -0
  100. data/generators/ccls_engine/templates/fixtures/data_sources.yml +40 -0
  101. data/generators/ccls_engine/templates/fixtures/diagnoses.yml +40 -0
  102. data/generators/ccls_engine/templates/fixtures/document_types.yml +65 -0
  103. data/generators/ccls_engine/templates/fixtures/document_versions.csv +155 -0
  104. data/generators/ccls_engine/templates/fixtures/follow_up_types.yml +16 -0
  105. data/generators/ccls_engine/templates/fixtures/hospitals.yml +114 -0
  106. data/generators/ccls_engine/templates/fixtures/ineligible_reasons.yml +35 -0
  107. data/generators/ccls_engine/templates/fixtures/instrument_types.yml +26 -0
  108. data/generators/ccls_engine/templates/fixtures/instrument_versions.yml +22 -0
  109. data/generators/ccls_engine/templates/fixtures/instruments.yml +22 -0
  110. data/generators/ccls_engine/templates/fixtures/interview_methods.yml +30 -0
  111. data/generators/ccls_engine/templates/fixtures/interview_outcomes.yml +31 -0
  112. data/generators/ccls_engine/templates/fixtures/languages.yml +34 -0
  113. data/generators/ccls_engine/templates/fixtures/operational_event_types.yml +141 -0
  114. data/generators/ccls_engine/templates/fixtures/organizations.yml +198 -0
  115. data/generators/ccls_engine/templates/fixtures/people.yml +130 -0
  116. data/generators/ccls_engine/templates/fixtures/phone_types.yml +30 -0
  117. data/generators/ccls_engine/templates/fixtures/project_outcomes.yml +25 -0
  118. data/generators/ccls_engine/templates/fixtures/projects.yml +59 -0
  119. data/generators/ccls_engine/templates/fixtures/races.yml +52 -0
  120. data/generators/ccls_engine/templates/fixtures/refusal_reasons.yml +55 -0
  121. data/generators/ccls_engine/templates/fixtures/sample_outcomes.yml +36 -0
  122. data/generators/ccls_engine/templates/fixtures/sample_temperatures.yml +16 -0
  123. data/generators/ccls_engine/templates/fixtures/sample_types.yml +147 -0
  124. data/generators/ccls_engine/templates/fixtures/sections.yml +31 -0
  125. data/generators/ccls_engine/templates/fixtures/states.yml +363 -0
  126. data/generators/ccls_engine/templates/fixtures/subject_relationships.yml +46 -0
  127. data/generators/ccls_engine/templates/fixtures/subject_types.yml +30 -0
  128. data/generators/ccls_engine/templates/fixtures/tracing_statuses.yml +30 -0
  129. data/generators/ccls_engine/templates/fixtures/units.yml +13 -0
  130. data/generators/ccls_engine/templates/fixtures/vital_statuses.yml +28 -0
  131. data/generators/ccls_engine/templates/functional/roles_controller_test.rb +142 -0
  132. data/generators/ccls_engine/templates/functional/sessions_controller_test.rb +19 -0
  133. data/generators/ccls_engine/templates/functional/users_controller_test.rb +94 -0
  134. data/generators/ccls_engine/templates/images/sort_down.png +0 -0
  135. data/generators/ccls_engine/templates/images/sort_up.png +0 -0
  136. data/generators/ccls_engine/templates/initializer.rb +28 -0
  137. data/generators/ccls_engine/templates/javascripts/ccls_engine.js +24 -0
  138. data/generators/ccls_engine/templates/javascripts/jquery-ui.js +763 -0
  139. data/generators/ccls_engine/templates/javascripts/jquery.js +154 -0
  140. data/generators/ccls_engine/templates/javascripts/jrails.js +1 -0
  141. data/generators/ccls_engine/templates/migrations/create_user_invitations.rb +18 -0
  142. data/generators/ccls_engine/templates/migrations/create_users.rb +33 -0
  143. data/generators/ccls_engine/templates/migrations/drop_user_invitations.rb +18 -0
  144. data/generators/ccls_engine/templates/stylesheets/ccls_engine.css +180 -0
  145. data/generators/ccls_engine/templates/stylesheets/user.css +35 -0
  146. data/generators/ccls_engine/templates/stylesheets/users.css +23 -0
  147. data/generators/ccls_engine/templates/unit/core_extension_test.rb +18 -0
  148. data/generators/ccls_engine/templates/unit/role_test.rb +30 -0
  149. data/generators/ccls_engine/templates/unit/user_test.rb +321 -0
  150. data/lib/ccls-ccls_engine.rb +1 -0
  151. data/lib/ccls_engine.rb +135 -0
  152. data/lib/ccls_engine/action_view_extension.rb +3 -0
  153. data/lib/ccls_engine/action_view_extension/base.rb +53 -0
  154. data/lib/ccls_engine/action_view_extension/form_builder.rb +39 -0
  155. data/lib/ccls_engine/active_record_extension.rb +2 -0
  156. data/lib/ccls_engine/active_record_extension/base.rb +70 -0
  157. data/lib/ccls_engine/active_record_shared.rb +8 -0
  158. data/lib/ccls_engine/assertions.rb +69 -0
  159. data/lib/ccls_engine/autotest.rb +54 -0
  160. data/lib/ccls_engine/ccls_user.rb +117 -0
  161. data/lib/ccls_engine/core_extension.rb +14 -0
  162. data/lib/ccls_engine/date_and_time_formats.rb +30 -0
  163. data/lib/ccls_engine/factories.rb +880 -0
  164. data/lib/ccls_engine/factory_test_helper.rb +276 -0
  165. data/lib/ccls_engine/helper.rb +112 -0
  166. data/lib/ccls_engine/icf_master_tracker_update_test_helper.rb +121 -0
  167. data/lib/ccls_engine/live_birth_data_update_test_helper.rb +110 -0
  168. data/lib/ccls_engine/package_test_helper.rb +49 -0
  169. data/lib/ccls_engine/shared_database.rb +20 -0
  170. data/lib/ccls_engine/tasks.rb +1 -0
  171. data/lib/ccls_engine/test_tasks.rb +52 -0
  172. data/lib/ccls_engine/translation_table.rb +86 -0
  173. data/lib/shared_migration.rb +5 -0
  174. data/lib/surveyor/survey_extensions.rb +125 -0
  175. data/lib/tasks/application.rake +286 -0
  176. data/lib/tasks/calnet_authenticated.rake +6 -0
  177. data/lib/tasks/common_lib.rake +7 -0
  178. data/lib/tasks/database.rake +288 -0
  179. data/lib/tasks/documentation.rake +71 -0
  180. data/lib/tasks/homex_import.rake +723 -0
  181. data/lib/tasks/odms_import.rake +1116 -0
  182. data/lib/tasks/simply_authorized.rake +6 -0
  183. data/lib/tasks/ucb_ccls_engine_tasks.rake +4 -0
  184. data/lib/tasks/use_db.rake +4 -0
  185. data/rails/init.rb +4 -0
  186. data/test/unit/ccls/abstract_search_test.rb +150 -0
  187. data/test/unit/ccls/abstract_test.rb +674 -0
  188. data/test/unit/ccls/address_test.rb +155 -0
  189. data/test/unit/ccls/address_type_test.rb +25 -0
  190. data/test/unit/ccls/addressing_test.rb +466 -0
  191. data/test/unit/ccls/aliquot_sample_format_test.rb +20 -0
  192. data/test/unit/ccls/aliquot_test.rb +156 -0
  193. data/test/unit/ccls/analysis_test.rb +31 -0
  194. data/test/unit/ccls/bc_request_test.rb +43 -0
  195. data/test/unit/ccls/candidate_control_test.rb +712 -0
  196. data/test/unit/ccls/context_data_source_test.rb +26 -0
  197. data/test/unit/ccls/context_test.rb +40 -0
  198. data/test/unit/ccls/core_extension_test.rb +17 -0
  199. data/test/unit/ccls/county_test.rb +34 -0
  200. data/test/unit/ccls/data_source_test.rb +41 -0
  201. data/test/unit/ccls/diagnosis_test.rb +51 -0
  202. data/test/unit/ccls/document_type_test.rb +35 -0
  203. data/test/unit/ccls/document_version_test.rb +68 -0
  204. data/test/unit/ccls/enrollment_test.rb +575 -0
  205. data/test/unit/ccls/follow_up_test.rb +23 -0
  206. data/test/unit/ccls/follow_up_type_test.rb +34 -0
  207. data/test/unit/ccls/gift_card_search_test.rb +153 -0
  208. data/test/unit/ccls/gift_card_test.rb +40 -0
  209. data/test/unit/ccls/home_exposure_response_test.rb +83 -0
  210. data/test/unit/ccls/homex_outcome_test.rb +199 -0
  211. data/test/unit/ccls/hospital_test.rb +102 -0
  212. data/test/unit/ccls/icf_master_id_test.rb +30 -0
  213. data/test/unit/ccls/icf_master_tracker_change_test.rb +14 -0
  214. data/test/unit/ccls/icf_master_tracker_test.rb +132 -0
  215. data/test/unit/ccls/icf_master_tracker_update_test.rb +176 -0
  216. data/test/unit/ccls/ineligible_reason_test.rb +48 -0
  217. data/test/unit/ccls/instrument_test.rb +62 -0
  218. data/test/unit/ccls/instrument_type_test.rb +39 -0
  219. data/test/unit/ccls/instrument_version_test.rb +71 -0
  220. data/test/unit/ccls/interview_method_test.rb +44 -0
  221. data/test/unit/ccls/interview_outcome_test.rb +34 -0
  222. data/test/unit/ccls/interview_test.rb +298 -0
  223. data/test/unit/ccls/language_test.rb +47 -0
  224. data/test/unit/ccls/live_birth_data_update_test.rb +358 -0
  225. data/test/unit/ccls/operational_event_test.rb +187 -0
  226. data/test/unit/ccls/operational_event_type_test.rb +51 -0
  227. data/test/unit/ccls/organization_test.rb +64 -0
  228. data/test/unit/ccls/patient_test.rb +538 -0
  229. data/test/unit/ccls/person_test.rb +55 -0
  230. data/test/unit/ccls/phone_number_test.rb +244 -0
  231. data/test/unit/ccls/phone_type_test.rb +32 -0
  232. data/test/unit/ccls/project_outcome_test.rb +34 -0
  233. data/test/unit/ccls/project_test.rb +60 -0
  234. data/test/unit/ccls/race_test.rb +37 -0
  235. data/test/unit/ccls/refusal_reason_test.rb +52 -0
  236. data/test/unit/ccls/role_test.rb +26 -0
  237. data/test/unit/ccls/sample_kit_test.rb +35 -0
  238. data/test/unit/ccls/sample_outcome_test.rb +34 -0
  239. data/test/unit/ccls/sample_temperature_test.rb +25 -0
  240. data/test/unit/ccls/sample_test.rb +363 -0
  241. data/test/unit/ccls/sample_type_test.rb +58 -0
  242. data/test/unit/ccls/section_test.rb +34 -0
  243. data/test/unit/ccls/state_test.rb +31 -0
  244. data/test/unit/ccls/study_subject_abstracts_test.rb +115 -0
  245. data/test/unit/ccls/study_subject_addresses_test.rb +93 -0
  246. data/test/unit/ccls/study_subject_duplicates_test.rb +407 -0
  247. data/test/unit/ccls/study_subject_enrollments_test.rb +65 -0
  248. data/test/unit/ccls/study_subject_homex_outcome_test.rb +64 -0
  249. data/test/unit/ccls/study_subject_identifier_test.rb +439 -0
  250. data/test/unit/ccls/study_subject_interviews_test.rb +26 -0
  251. data/test/unit/ccls/study_subject_languages_test.rb +142 -0
  252. data/test/unit/ccls/study_subject_operational_events_test.rb +53 -0
  253. data/test/unit/ccls/study_subject_patient_test.rb +249 -0
  254. data/test/unit/ccls/study_subject_pii_test.rb +278 -0
  255. data/test/unit/ccls/study_subject_races_test.rb +203 -0
  256. data/test/unit/ccls/study_subject_search_test.rb +704 -0
  257. data/test/unit/ccls/study_subject_test.rb +770 -0
  258. data/test/unit/ccls/subject_language_test.rb +43 -0
  259. data/test/unit/ccls/subject_race_test.rb +35 -0
  260. data/test/unit/ccls/subject_relationship_test.rb +43 -0
  261. data/test/unit/ccls/subject_type_test.rb +40 -0
  262. data/test/unit/ccls/tracing_status_test.rb +32 -0
  263. data/test/unit/ccls/transfer_test.rb +81 -0
  264. data/test/unit/ccls/translation_table_test.rb +40 -0
  265. data/test/unit/ccls/unit_test.rb +21 -0
  266. data/test/unit/ccls/user_test.rb +156 -0
  267. data/test/unit/ccls/vital_status_test.rb +36 -0
  268. data/test/unit/ccls/zip_code_test.rb +55 -0
  269. metadata +633 -0
@@ -0,0 +1,4 @@
1
+ class ContextDataSource < ActiveRecordShared
2
+ belongs_to :context
3
+ belongs_to :data_source
4
+ end
@@ -0,0 +1,16 @@
1
+ class County < ActiveRecordShared
2
+
3
+ default_scope :order => :name
4
+ has_many :zip_codes
5
+
6
+ validates_presence_of :name
7
+ validates_length_of :name, :maximum => 250
8
+ validates_presence_of :state_abbrev
9
+ validates_length_of :state_abbrev, :maximum => 2
10
+ validates_length_of :fips_code, :maximum => 5, :allow_nil => true
11
+
12
+ def to_s
13
+ "#{name}, #{state_abbrev}"
14
+ end
15
+
16
+ end
@@ -0,0 +1,24 @@
1
+ # don't know exactly
2
+ class DataSource < ActiveRecordShared
3
+
4
+ acts_as_list
5
+ default_scope :order => :position
6
+
7
+ acts_like_a_hash
8
+
9
+ validates_length_of :data_origin,
10
+ :other_organization, :other_person,
11
+ :maximum => 250, :allow_blank => true
12
+
13
+ # Returns description
14
+ def to_s
15
+ description
16
+ end
17
+
18
+ # Returns boolean of comparison
19
+ # true only if key == 'other'
20
+ def is_other?
21
+ key == 'other'
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ # don't know
2
+ class Diagnosis < ActiveRecordShared
3
+
4
+ acts_as_list
5
+ default_scope :order => :position
6
+
7
+ acts_like_a_hash
8
+
9
+ validates_presence_of :code
10
+ validates_uniqueness_of :code
11
+
12
+ # Return description
13
+ def to_s
14
+ description
15
+ end
16
+
17
+ # Returns boolean of comparison
18
+ # true only if key == 'other'
19
+ def is_other?
20
+ key == 'other'
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ class DocumentType < ActiveRecordShared
2
+
3
+ acts_as_list
4
+ default_scope :order => :position
5
+
6
+ has_many :document_versions
7
+
8
+ validates_presence_of :title
9
+ validates_length_of :title, :maximum => 250, :allow_blank => true
10
+ validates_length_of :description, :maximum => 250, :allow_blank => true
11
+
12
+ def to_s
13
+ title
14
+ end
15
+
16
+ end
@@ -0,0 +1,27 @@
1
+ class DocumentVersion < ActiveRecordShared
2
+
3
+ acts_as_list
4
+ default_scope :order => 'position, title ASC'
5
+
6
+ belongs_to :document_type
7
+ belongs_to :language
8
+ has_many :enrollments
9
+
10
+ validates_presence_of :document_type_id
11
+ validates_presence_of :document_type, :if => :document_type_id
12
+
13
+ validates_length_of :title, :maximum => 250, :allow_blank => true
14
+ validates_length_of :description, :maximum => 250, :allow_blank => true
15
+ validates_length_of :indicator, :maximum => 250, :allow_blank => true
16
+
17
+ validates_complete_date_for :began_use_on, :allow_nil => true
18
+ validates_complete_date_for :ended_use_on, :allow_nil => true
19
+
20
+ # Return title
21
+ def to_s
22
+ title
23
+ end
24
+
25
+ named_scope :type1, :conditions => { :document_type_id => 1 }
26
+
27
+ end
@@ -0,0 +1,78 @@
1
+ # Rich join of Subject and Project
2
+ # == requires
3
+ # * project
4
+ class Enrollment < ActiveRecordShared
5
+
6
+ belongs_to :study_subject
7
+ belongs_to :ineligible_reason
8
+ belongs_to :refusal_reason
9
+ belongs_to :document_version
10
+ belongs_to :project
11
+ belongs_to :project_outcome
12
+ belongs_to :tracing_status
13
+ has_many :operational_events
14
+ has_many :follow_ups
15
+ has_many :samples
16
+
17
+ attr_protected :study_subject_id, :study_subject
18
+
19
+ delegate :is_other?, :to => :ineligible_reason, :allow_nil => true, :prefix => true
20
+ delegate :is_other?, :to => :refusal_reason, :allow_nil => true, :prefix => true
21
+
22
+ include EnrollmentValidations
23
+
24
+ # use after_save, rather than before_save,
25
+ # so that enrollment exists and can be used to create
26
+ # the operational event as the enrollment is validated
27
+ # before_save :create_enrollment_update,
28
+ after_save :create_enrollment_update,
29
+ :if => :is_complete_changed?
30
+
31
+ after_save :create_subject_consents_operational_event,
32
+ :if => :consented_changed?
33
+
34
+ after_save :create_subject_declines_operational_event,
35
+ :if => :consented_changed?
36
+
37
+ named_scope :consented, :conditions => { :consented => YNDK[:yes] }
38
+
39
+ protected
40
+
41
+ def create_enrollment_update
42
+ operational_event_type, occurred_on = if( is_complete == YNDK[:yes] )
43
+ [OperationalEventType['complete'], completed_on]
44
+ elsif( is_complete_was == YNDK[:yes] )
45
+ [OperationalEventType['reopened'], Date.today]
46
+ else
47
+ [nil, nil]
48
+ end
49
+ unless operational_event_type.nil?
50
+ OperationalEvent.create!(
51
+ :enrollment => self,
52
+ :operational_event_type => operational_event_type,
53
+ :occurred_on => occurred_on
54
+ )
55
+ end
56
+ end
57
+
58
+ def create_subject_consents_operational_event
59
+ if( ( consented == YNDK[:yes] ) and ( consented_was != YNDK[:yes] ) )
60
+ OperationalEvent.create!(
61
+ :enrollment => self,
62
+ :operational_event_type => OperationalEventType['subjectConsents'],
63
+ :occurred_on => consented_on
64
+ )
65
+ end
66
+ end
67
+
68
+ def create_subject_declines_operational_event
69
+ if( ( consented == YNDK[:no] ) and ( consented_was != YNDK[:no] ) )
70
+ OperationalEvent.create!(
71
+ :enrollment => self,
72
+ :operational_event_type => OperationalEventType['subjectDeclines'],
73
+ :occurred_on => consented_on
74
+ )
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,167 @@
1
+ #
2
+ # Simply extracted some code to clean up model.
3
+ # I'd like to do this to all of the really big classes
4
+ # but let's see how this goes first.
5
+ #
6
+ module EnrollmentValidations
7
+ def self.included(base)
8
+ # Must delay the calls to these ActiveRecord methods
9
+ # or it will raise many "undefined method"s.
10
+ base.class_eval do
11
+
12
+ validates_presence_of :project_id
13
+ validates_presence_of :project, :if => :project_id
14
+ validates_uniqueness_of :project_id, :scope => [:study_subject_id], :allow_blank => true
15
+
16
+ validates_length_of :notes, :maximum => 65000, :allow_blank => true
17
+
18
+ validates_presence_of :ineligible_reason_id,
19
+ :message => 'required if is_eligible is No',
20
+ :if => :is_not_eligible?
21
+ validates_absence_of :ineligible_reason_id,
22
+ :message => 'not allowed unless is_eligible is No',
23
+ :unless => :is_not_eligible?
24
+ validates_presence_of :ineligible_reason, :if => :ineligible_reason_id
25
+
26
+ validates_presence_of :ineligible_reason_specify,
27
+ :message => 'required if ineligible reason is Other',
28
+ :if => :ineligible_reason_is_other?
29
+ validates_absence_of :ineligible_reason_specify,
30
+ :message => 'not allowed unless is_eligible is No',
31
+ :unless => :is_not_eligible?
32
+
33
+ validates_presence_of :reason_not_chosen,
34
+ :message => 'requires if is_chosen is No',
35
+ :if => :is_not_chosen?
36
+ validates_absence_of :reason_not_chosen,
37
+ :message => 'not allowed unless is_chosen is No',
38
+ :unless => :is_not_chosen?
39
+
40
+ validates_presence_of :refusal_reason_id,
41
+ :message => "required if consented is No",
42
+ :if => :not_consented?
43
+ validates_absence_of :refusal_reason_id,
44
+ :message => "not allowed unless consented is No",
45
+ :unless => :not_consented?
46
+ validates_presence_of :refusal_reason, :if => :refusal_reason_id
47
+
48
+ # validates_presence_of :consented_on,
49
+ # :message => 'date is required when adding consent information',
50
+ # :if => :consented?
51
+ validates_presence_of :consented_on,
52
+ :message => 'date is required when adding consent information',
53
+ :unless => :consent_unknown?
54
+ # :if => :not_consented?
55
+ validates_absence_of :consented_on,
56
+ :message => "not allowed if consented is blank or Don't Know",
57
+ :if => :consent_unknown?
58
+ validates_past_date_for :consented_on
59
+
60
+ validates_presence_of :other_refusal_reason,
61
+ :message => "required if refusal reason is Other",
62
+ :if => :refusal_reason_is_other?
63
+ validates_absence_of :other_refusal_reason,
64
+ :message => "not allowed unless consented is No",
65
+ :unless => :not_consented?
66
+
67
+ validates_presence_of :terminated_reason,
68
+ :message => "required if terminated participation is Yes",
69
+ :if => :terminated_participation?
70
+ validates_absence_of :terminated_reason,
71
+ :message => "not allowed unless terminated participation is Yes",
72
+ :unless => :terminated_participation?
73
+
74
+ validates_presence_of :completed_on,
75
+ :message => "required if is_complete is Yes",
76
+ :if => :is_complete?
77
+ validates_absence_of :completed_on,
78
+ :message => "not allowed unless is_complete is Yes",
79
+ :unless => :is_complete?
80
+ validates_past_date_for :completed_on
81
+
82
+ validates_absence_of :document_version_id,
83
+ :message => "not allowed if consented is blank or Don't Know",
84
+ :if => :consent_unknown?
85
+ validates_presence_of :document_version, :if => :document_version_id
86
+
87
+ validates_complete_date_for :consented_on, :allow_nil => true
88
+ validates_complete_date_for :completed_on, :allow_nil => true
89
+
90
+ validates_length_of :recruitment_priority, :maximum => 250, :allow_blank => true
91
+ validates_length_of :ineligible_reason_specify, :maximum => 250, :allow_blank => true
92
+ validates_length_of :other_refusal_reason, :maximum => 250, :allow_blank => true
93
+ validates_length_of :reason_not_chosen, :maximum => 250, :allow_blank => true
94
+ validates_length_of :terminated_reason, :maximum => 250, :allow_blank => true
95
+ validates_length_of :reason_closed, :maximum => 250, :allow_blank => true
96
+
97
+
98
+ validates_inclusion_of :consented, :is_eligible,
99
+ :is_chosen, :is_complete, :terminated_participation,
100
+ :is_candidate,
101
+ :in => YNDK.valid_values, :allow_nil => true
102
+
103
+ validates_inclusion_of :use_smp_future_rsrch,
104
+ :use_smp_future_cancer_rsrch, :use_smp_future_other_rsrch,
105
+ :share_smp_with_others, :contact_for_related_study,
106
+ :provide_saliva_smp, :receive_study_findings,
107
+ :in => ADNA.valid_values, :allow_nil => true
108
+
109
+
110
+ #
111
+ # NOTE: BEWARE of POSSIBLE strings in these comparisons.
112
+ # Rails SHOULD actually convert the incoming
113
+ # params (which are strings) to integers or nil.
114
+ #
115
+
116
+ # Return boolean of comparison
117
+ # true only if is_eligible == 2
118
+ def is_not_eligible?
119
+ # is_eligible.to_i == YNDK[:no] #2
120
+ is_eligible == YNDK[:no] #2
121
+ end
122
+
123
+ # Return boolean of comparison
124
+ # true only if is_chosen == 2
125
+ def is_not_chosen?
126
+ # is_chosen.to_i == YNDK[:no] #2
127
+ is_chosen == YNDK[:no] #2
128
+ end
129
+
130
+ # Return boolean of comparison
131
+ # true only if consented == 1
132
+ # no longer used, I believe
133
+ # def consented?
134
+ # consented == 1
135
+ # end
136
+
137
+ # Return boolean of comparison
138
+ # true only if consented == 2
139
+ def not_consented?
140
+ # consented.to_i == YNDK[:no] #2
141
+ consented == YNDK[:no] #2
142
+ end
143
+
144
+ # Return boolean of comparison
145
+ # true only if consented == nil or 999
146
+ def consent_unknown?
147
+ # [nil,999,'','999'].include?(consented) # not 1 or 2
148
+ [nil,999].include?(consented) # not 1 or 2
149
+ end
150
+
151
+ # Return boolean of comparison
152
+ # true only if terminated_participation == 1
153
+ def terminated_participation?
154
+ # terminated_participation.to_i == YNDK[:yes] # 1
155
+ terminated_participation == YNDK[:yes] # 1
156
+ end
157
+
158
+ # Return boolean of comparison
159
+ # true only if is_complete == 1
160
+ def is_complete?
161
+ # is_complete.to_i == YNDK[:yes] # 1
162
+ is_complete == YNDK[:yes] # 1
163
+ end
164
+
165
+ end # class_eval
166
+ end # included
167
+ end # EnrollmentValidations
@@ -0,0 +1,16 @@
1
+ class FollowUp < ActiveRecordShared
2
+
3
+ # with these null = false lines,
4
+ # there should really be validations
5
+ # or remove these.
6
+ # t.integer :section_id, :null => false
7
+ # t.integer :enrollment_id, :null => false
8
+ # t.integer :follow_up_type_id, :null => false
9
+
10
+ belongs_to :section
11
+ belongs_to :enrollment
12
+ belongs_to :follow_up_type
13
+
14
+ attr_accessor :current_user
15
+
16
+ end
@@ -0,0 +1,18 @@
1
+ # == requires
2
+ # * key ( unique )
3
+ # * description ( > 3 chars )
4
+ class FollowUpType < ActiveRecordShared
5
+
6
+ acts_as_list
7
+ default_scope :order => :position
8
+
9
+ acts_like_a_hash
10
+
11
+ has_many :follow_ups
12
+
13
+ # Returns description
14
+ def to_s
15
+ description
16
+ end
17
+
18
+ end
@@ -0,0 +1,22 @@
1
+ class GiftCard < ActiveRecordShared
2
+
3
+ belongs_to :study_subject
4
+ attr_protected :study_subject_id, :study_subject
5
+ belongs_to :project
6
+
7
+ validates_presence_of :number
8
+ validates_length_of :number, :maximum => 250, :allow_blank => true
9
+ validates_uniqueness_of :number
10
+ validates_length_of :expiration, :maximum => 250, :allow_blank => true
11
+ validates_length_of :vendor, :maximum => 250, :allow_blank => true
12
+
13
+ def to_s
14
+ number
15
+ end
16
+
17
+ # include GiftCardSearch
18
+ def self.search(params={})
19
+ GiftCardSearch.new(params).gift_cards
20
+ end
21
+
22
+ end
@@ -0,0 +1,137 @@
1
+ #module GiftCardSearch
2
+ #def self.included(base)
3
+ ## Must delay the calls to these ActiveRecord methods
4
+ ## or it will raise many "undefined method"s.
5
+ #base.class_eval do
6
+ #
7
+ # def self.valid_search_orders
8
+ # {
9
+ # :id => 'gift_cards.id',
10
+ # :childid => 'study_subjects.childid',
11
+ # :last_name => 'study_subjects.last_name',
12
+ # :first_name => 'study_subjects.first_name',
13
+ # :studyid => 'study_subjects.patid',
14
+ # :number => 'gift_cards.number',
15
+ # :issued_on => 'gift_cards.issued_on'
16
+ # }.with_indifferent_access
17
+ # end
18
+ #
19
+ # def self.search(params={})
20
+ # params = params.dup.with_indifferent_access
21
+ # paginate_search = params.has_key?(:paginate) && params[:paginate]
22
+ # per_page = params[:per_page]
23
+ # page = params[:page]
24
+ # q = params.has_key?(:q) && params[:q]
25
+ # conditions = if q.blank?
26
+ # nil
27
+ # else
28
+ # c = []
29
+ # v = {}
30
+ # q.to_s.split(/\s+/).each_with_index do |t,i|
31
+ # c.push("gift_cards.number LIKE :t#{i}")
32
+ # c.push("study_subjects.first_name LIKE :t#{i}")
33
+ # c.push("study_subjects.last_name LIKE :t#{i}")
34
+ # c.push("study_subjects.patid LIKE :t#{i}")
35
+ # c.push("study_subjects.childid LIKE :t#{i}")
36
+ # v["t#{i}".to_sym] = "%#{t}%"
37
+ # end
38
+ # [ "( #{c.join(' OR ')} )", v ]
39
+ # end
40
+ #
41
+ # order = params.has_key?(:order) && params[:order]
42
+ # dir = params[:dir]
43
+ # search_order = if valid_search_orders.has_key?(order)
44
+ # order_string = valid_search_orders[order]
45
+ # dir = case dir.try(:downcase)
46
+ # when 'desc' then 'desc'
47
+ # else 'asc'
48
+ # end
49
+ # [order_string,dir].join(' ')
50
+ # else
51
+ # nil
52
+ # end
53
+ #
54
+ # GiftCard.send(
55
+ # (paginate_search)?'paginate':'all',{
56
+ # :order => search_order,
57
+ # :joins => "LEFT JOIN study_subjects ON gift_cards.study_subject_id = study_subjects.id",
58
+ # :conditions => conditions
59
+ # }.merge(
60
+ # (paginate_search)?{
61
+ # :per_page => per_page||25,
62
+ # :page => page||1
63
+ # }:{}
64
+ # )
65
+ # )
66
+ # end
67
+ #
68
+ #end # class_eval
69
+ #end # included
70
+ #end # GiftCardSearch
71
+ #
72
+ #
73
+ #__END__
74
+
75
+ # This is only ever used in HomeX which is going to go away.
76
+
77
+
78
+ class GiftCardSearch < Search
79
+
80
+ self.searchable_attributes += [ :q, :number ]
81
+
82
+ # self.valid_orders.merge!({ # NO!
83
+ # @valid_orders.merge!({ # NO!
84
+ self.valid_orders = self.valid_orders.merge({
85
+ :id => nil,
86
+ :childid => 'study_subjects.childid',
87
+ :last_name => 'study_subjects.last_name',
88
+ :first_name => 'study_subjects.first_name',
89
+ :studyid => 'study_subjects.patid',
90
+ :number => nil,
91
+ :issued_on => nil
92
+ })
93
+
94
+ def gift_cards
95
+ @gift_cards ||= GiftCard.send(
96
+ (paginate?)?'paginate':'all',{
97
+ :order => search_order,
98
+ :joins => joins,
99
+ :conditions => conditions
100
+ }.merge(
101
+ (paginate?)?{
102
+ :per_page => per_page||25,
103
+ :page => page||1
104
+ }:{}
105
+ )
106
+ )
107
+ end
108
+
109
+ private # THIS IS REQUIRED
110
+
111
+ def q_conditions
112
+ unless q.blank?
113
+ c = []
114
+ v = {}
115
+ q.to_s.split(/\s+/).each_with_index do |t,i|
116
+ c.push("gift_cards.number LIKE :t#{i}")
117
+ c.push("study_subjects.first_name LIKE :t#{i}")
118
+ c.push("study_subjects.last_name LIKE :t#{i}")
119
+ c.push("study_subjects.patid LIKE :t#{i}")
120
+ c.push("study_subjects.childid LIKE :t#{i}")
121
+ v["t#{i}".to_sym] = "%#{t}%"
122
+ end
123
+ [ "( #{c.join(' OR ')} )", v ]
124
+ end
125
+ end
126
+
127
+ def study_subjects_joins
128
+ "LEFT JOIN study_subjects ON gift_cards.study_subject_id = study_subjects.id"
129
+ end
130
+
131
+ # # must come before other study_subject related joins
132
+ # def a_subjects_joins
133
+ # "LEFT JOIN study_subjects ON gift_cards.study_subject_id = study_subjects.id" if(
134
+ # %w(childid studyid last_name first_name).include?(@order) )
135
+ # end
136
+
137
+ end