ccls-ccls_engine 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
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,52 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::RefusalReasonTest < ActiveSupport::TestCase
4
+
5
+ assert_should_behave_like_a_hash
6
+
7
+ # Only IF study_subject not consented
8
+ # assert_should_have_many(:enrollments)
9
+
10
+ assert_should_create_default_object
11
+ assert_should_act_as_list
12
+ assert_should_not_require_attributes( :position )
13
+
14
+ test "explicit Factory refusal_reason test" do
15
+ assert_difference('RefusalReason.count',1) {
16
+ refusal_reason = Factory(:refusal_reason)
17
+ assert_match /Key\d*/, refusal_reason.key
18
+ assert_match /Desc\d*/, refusal_reason.description
19
+ }
20
+ end
21
+
22
+ test "should return description as to_s" do
23
+ refusal_reason = create_refusal_reason
24
+ assert_equal refusal_reason.description, "#{refusal_reason}"
25
+ end
26
+
27
+ test "should find random" do
28
+ refusal_reason = RefusalReason.random()
29
+ assert refusal_reason.is_a?(RefusalReason)
30
+ end
31
+
32
+ test "should return nil on random when no records" do
33
+ # RefusalReason.destroy_all
34
+ RefusalReason.stubs(:count).returns(0)
35
+ refusal_reason = RefusalReason.random()
36
+ assert_nil refusal_reason
37
+ end
38
+
39
+ test "should return true for is_other if is other" do
40
+ refusal_reason = RefusalReason['Other']
41
+ assert refusal_reason.is_other?
42
+ end
43
+
44
+ #protected
45
+ #
46
+ # def create_refusal_reason(options={})
47
+ # refusal_reason = Factory.build(:refusal_reason,options)
48
+ # refusal_reason.save
49
+ # refusal_reason
50
+ # end
51
+
52
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::RoleTest < ActiveSupport::TestCase
4
+
5
+ assert_should_act_as_list
6
+ assert_should_require(:name)
7
+ assert_should_require_unique(:name)
8
+ assert_should_habtm(:users)
9
+
10
+ test "should create role" do
11
+ assert_difference('Role.count',1) do
12
+ role = create_role
13
+ assert !role.new_record?,
14
+ "#{role.errors.full_messages.to_sentence}"
15
+ end
16
+ end
17
+
18
+ #protected
19
+ #
20
+ # def create_role(options = {})
21
+ # role = Factory.build(:role,options)
22
+ # role.save
23
+ # role
24
+ # end
25
+
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::SampleKitTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_initially_belong_to( :sample )
7
+ assert_should_require_unique_attribute( :sample_id )
8
+
9
+ test "explicit Factory sample_kit test" do
10
+ assert_difference('Sample.count',1) {
11
+ assert_difference('SampleKit.count',1) {
12
+ sample_kit = Factory(:sample_kit)
13
+ assert_not_nil sample_kit.sample
14
+ } }
15
+ end
16
+
17
+ test "should require a unique sample" do
18
+ assert_difference( "SampleKit.count", 1 ) {
19
+ assert_difference('Sample.count', 1) {
20
+ sample_kit = create_sample_kit
21
+ assert_not_nil sample_kit.sample
22
+ sample_kit = create_sample_kit(:sample_id => sample_kit.sample_id)
23
+ assert sample_kit.errors.on(:sample_id)
24
+ } }
25
+ end
26
+
27
+ #protected
28
+ #
29
+ # def create_sample_kit(options={})
30
+ # sample_kit = Factory.build(:sample_kit,options)
31
+ # sample_kit.save
32
+ # sample_kit
33
+ # end
34
+
35
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::SampleOutcomeTest < ActiveSupport::TestCase
4
+
5
+ assert_should_behave_like_a_hash
6
+
7
+ assert_should_create_default_object
8
+ assert_should_act_as_list
9
+ assert_should_have_many( :homex_outcomes )
10
+ assert_should_not_require_attributes( :position )
11
+
12
+ test "explicit Factory sample_outcome test" do
13
+ assert_difference('SampleOutcome.count',1) {
14
+ sample_outcome = Factory(:sample_outcome)
15
+ assert_match /Key\d*/, sample_outcome.key
16
+ assert_match /Desc\d*/, sample_outcome.description
17
+ }
18
+ end
19
+
20
+ test "should return description as to_s" do
21
+ sample_outcome = create_sample_outcome(:description => "Description")
22
+ assert_equal sample_outcome.description,
23
+ "#{sample_outcome}"
24
+ end
25
+
26
+ #protected
27
+ #
28
+ # def create_sample_outcome(options={})
29
+ # sample_outcome = Factory.build(:sample_outcome,options)
30
+ # sample_outcome.save
31
+ # sample_outcome
32
+ # end
33
+
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::SampleTemperatureTest < ActiveSupport::TestCase
4
+
5
+ assert_should_behave_like_a_hash
6
+
7
+ assert_should_create_default_object
8
+ assert_should_act_as_list
9
+ assert_should_not_require_attributes( :position )
10
+ assert_should_have_many(:samples)
11
+
12
+ test "explicit Factory sample temperature test" do
13
+ assert_difference('SampleTemperature.count',1) {
14
+ sample_temperature = Factory(:sample_temperature)
15
+ assert_match /Key\d*/, sample_temperature.key
16
+ assert_match /Desc\d*/, sample_temperature.description
17
+ }
18
+ end
19
+
20
+ test "should return description as to_s" do
21
+ sample_temperature = create_sample_temperature
22
+ assert_equal sample_temperature.description, "#{sample_temperature}"
23
+ end
24
+
25
+ end
@@ -0,0 +1,363 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::SampleTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_have_one( :sample_kit )
7
+ assert_should_have_many( :aliquots )
8
+ assert_should_belong_to( :aliquot_sample_format, :unit,
9
+ :organization, :sample_temperature )
10
+ assert_should_initially_belong_to( :study_subject, :project, :sample_type )
11
+
12
+ assert_should_protect(:study_subject_id, :study_subject)
13
+
14
+ assert_should_not_require_attributes( :position,
15
+ :parent_sample_id,
16
+ :sample_collector_id,
17
+ :sample_temperature,
18
+ :sample_temperature_id,
19
+ :aliquot_sample_format,
20
+ :aliquot_sample_format_id,
21
+ :unit,
22
+ :unit_id,
23
+ :order_no,
24
+ :quantity_in_sample,
25
+ :aliquot_or_sample_on_receipt,
26
+ :sent_to_subject_on,
27
+ :collected_at,
28
+ :received_by_ccls_at,
29
+ :sent_to_lab_on,
30
+ :received_by_lab_on,
31
+ :aliquotted_on,
32
+ :external_id,
33
+ :external_id_source,
34
+ :receipt_confirmed_on,
35
+ :receipt_confirmed_by,
36
+ :location_id )
37
+
38
+ # TODO These seem to fail for DateTimes. Need to check it out.
39
+ assert_requires_complete_date( :sent_to_subject_on,
40
+ # :received_by_ccls_at,
41
+ :sent_to_lab_on,
42
+ :received_by_lab_on, :aliquotted_on,
43
+ # :collected_at,
44
+ :receipt_confirmed_on )
45
+
46
+ assert_requires_past_date( :sent_to_subject_on,
47
+ :received_by_ccls_at, :sent_to_lab_on,
48
+ :received_by_lab_on, :aliquotted_on,
49
+ :receipt_confirmed_on, :collected_at )
50
+
51
+ test "explicit Factory sample test" do
52
+ assert_difference('StudySubject.count',1) {
53
+ assert_difference('Enrollment.count',1) {
54
+ assert_difference('SampleType.count',2) { # creates sample_type and a parent sample_type
55
+ assert_difference('Sample.count',1) {
56
+ assert_difference('Project.count',1) {
57
+ sample = Factory(:sample)
58
+ assert_not_nil sample.sample_type
59
+ assert_not_nil sample.sample_type.parent
60
+ assert_not_nil sample.study_subject
61
+ assert_not_nil sample.project
62
+ } } } } }
63
+ end
64
+
65
+ test "should require sample_type" do
66
+ assert_difference( "Sample.count", 0 ) do
67
+ sample = create_sample( :sample_type => nil)
68
+ assert !sample.errors.on(:sample_type)
69
+ assert sample.errors.on_attr_and_type?(:sample_type_id,:blank)
70
+ end
71
+ end
72
+
73
+ test "should require valid sample_type" do
74
+ assert_difference( "Sample.count", 0 ) do
75
+ sample = create_sample( :sample_type_id => 0)
76
+ assert !sample.errors.on(:sample_type_id)
77
+ assert sample.errors.on_attr_and_type?(:sample_type,:blank)
78
+ end
79
+ end
80
+
81
+ test "should require study_subject" do
82
+ assert_difference( "Sample.count", 0 ) do
83
+ sample = create_sample( :study_subject => nil)
84
+ assert !sample.errors.on(:study_subject)
85
+ assert sample.errors.on_attr_and_type?(:study_subject_id,:blank)
86
+ end
87
+ end
88
+
89
+ test "should require valid study_subject" do
90
+ assert_difference( "Sample.count", 0 ) do
91
+ sample = create_sample( :study_subject_id => 0)
92
+ assert !sample.errors.on(:study_subject_id)
93
+ assert sample.errors.on_attr_and_type?(:study_subject,:blank)
94
+ end
95
+ end
96
+
97
+ test "should require project" do
98
+ assert_difference( "Sample.count", 0 ) do
99
+ sample = create_sample( :project => nil)
100
+ assert !sample.errors.on(:project)
101
+ assert sample.errors.on_attr_and_type?(:project_id,:blank)
102
+ end
103
+ end
104
+
105
+ test "should require valid project" do
106
+ assert_difference( "Sample.count", 0 ) do
107
+ sample = create_sample( :project_id => 0)
108
+ assert !sample.errors.on(:project_id)
109
+ assert sample.errors.on_attr_and_type?(:project,:blank)
110
+ end
111
+ end
112
+
113
+ test "should default order_no to 1" do
114
+ sample = create_sample
115
+ assert_equal 1, sample.order_no
116
+ end
117
+
118
+ test "should default aliquot_or_sample_on_receipt to 'Sample'" do
119
+ sample = create_sample
120
+ assert_equal 'Sample', sample.aliquot_or_sample_on_receipt
121
+ end
122
+
123
+ # somehow, through location_id I think
124
+
125
+ # TODO haven't really implemented organization samples yet
126
+ # test "should belong to organization" do
127
+ # sample = create_sample
128
+ # assert_nil sample.organization
129
+ # sample.organization = Factory(:organization)
130
+ # assert_not_nil sample.organization
131
+ # # this is not clear in my UML diagram
132
+ # pending
133
+ # end
134
+
135
+
136
+ # I get this in the functional tests, but I can't seem
137
+ # to reproduce it here.
138
+ # ArgumentError: comparison of Date with ActiveSupport::TimeWithZone failed
139
+
140
+ #ArgumentError (comparison of Date with ActiveSupport::TimeWithZone failed):
141
+ # /Library/Ruby/Gems/1.8/gems/ccls-ccls_engine-3.10.0/app/models/sample.rb:77:in `>'
142
+ # /Library/Ruby/Gems/1.8/gems/ccls-ccls_engine-3.10.0/app/models/sample.rb:77:in `collected_at_is_before_sent_to_subject_on?'
143
+ # /Library/Ruby/Gems/1.8/gems/ccls-ccls_engine-3.10.0/app/models/sample.rb:64:in `date_chronology'
144
+
145
+ # Even if the *_at field is given a Date value, it will be typecast to ActiveSupport::TimeWithZone so there is no terrible need to update all of the tests to send one.
146
+
147
+
148
+ test "should require sent_to_subject_on if collected_at" do
149
+ assert_difference( 'Sample.count', 0 ) do
150
+ sample = create_sample(
151
+ :sent_to_subject_on => nil,
152
+ :collected_at => Date.yesterday
153
+ )
154
+ assert sample.errors.on(:sent_to_subject_on)
155
+ assert_match(/be blank/,
156
+ sample.errors.on(:sent_to_subject_on) )
157
+ end
158
+ end
159
+
160
+ test "should require collected_at be after sent_to_subject_on" do
161
+ assert_difference( 'Sample.count', 0 ) do
162
+ sample = create_sample(
163
+ :sent_to_subject_on => Date.tomorrow,
164
+ :collected_at => Date.yesterday
165
+ )
166
+ assert sample.errors.on(:collected_at)
167
+ assert_match(/after sent_to_subject_on/,
168
+ sample.errors.on(:collected_at) )
169
+ end
170
+ end
171
+
172
+ test "should require collected_at if received_by_ccls_at" do
173
+ assert_difference( 'Sample.count', 0 ) do
174
+ sample = create_sample(
175
+ :collected_at => nil,
176
+ :received_by_ccls_at => Date.yesterday
177
+ )
178
+ assert sample.errors.on(:collected_at)
179
+ assert_match(/be blank/,
180
+ sample.errors.on(:collected_at) )
181
+ end
182
+ end
183
+
184
+ test "should require received_by_ccls_at be after collected_at" do
185
+ assert_difference( 'Sample.count', 0 ) do
186
+ sample = create_sample(
187
+ :collected_at => Date.tomorrow,
188
+ :received_by_ccls_at => Date.yesterday
189
+ )
190
+ assert sample.errors.on(:received_by_ccls_at)
191
+ assert_match(/after collected_at/,
192
+ sample.errors.on(:received_by_ccls_at) )
193
+ end
194
+ end
195
+
196
+ test "should require received_by_ccls_at if sent_to_lab_on" do
197
+ assert_difference( 'Sample.count', 0 ) do
198
+ sample = create_sample(
199
+ :received_by_ccls_at => nil,
200
+ :sent_to_lab_on => Date.yesterday
201
+ )
202
+ assert sample.errors.on(:received_by_ccls_at)
203
+ assert_match(/be blank/,
204
+ sample.errors.on(:received_by_ccls_at) )
205
+ end
206
+ end
207
+
208
+ test "should require sent_to_lab_on be after received_by_ccls_at" do
209
+ assert_difference( 'Sample.count', 0 ) do
210
+ sample = create_sample(
211
+ :received_by_ccls_at => Date.tomorrow,
212
+ :received_by_ccls_at => ( DateTime.now + 1.day ),
213
+ :sent_to_lab_on => Date.yesterday
214
+ )
215
+ assert sample.errors.on(:sent_to_lab_on)
216
+ assert_match(/after received_by_ccls_at/,
217
+ sample.errors.on(:sent_to_lab_on) )
218
+ end
219
+ end
220
+
221
+ test "should require sent_to_lab_on if received_by_lab_on" do
222
+ assert_difference( 'Sample.count', 0 ) do
223
+ sample = create_sample(
224
+ :sent_to_lab_on => nil,
225
+ :received_by_lab_on => Date.yesterday
226
+ )
227
+ assert sample.errors.on(:sent_to_lab_on)
228
+ assert_match(/be blank/,
229
+ sample.errors.on(:sent_to_lab_on) )
230
+ end
231
+ end
232
+
233
+ test "should require received_by_lab_on be after sent_to_lab_on" do
234
+ assert_difference( 'Sample.count', 0 ) do
235
+ sample = create_sample(
236
+ :sent_to_lab_on => Date.tomorrow,
237
+ :received_by_lab_on => Date.yesterday
238
+ )
239
+ assert sample.errors.on(:received_by_lab_on)
240
+ assert_match(/after sent_to_lab_on/,
241
+ sample.errors.on(:received_by_lab_on) )
242
+ end
243
+ end
244
+
245
+ test "should require location_id be after sent_to_lab_on" do
246
+ assert_difference( 'Sample.count', 0 ) do
247
+ sample = create_sample(
248
+ :sent_to_lab_on => Date.yesterday
249
+ )
250
+ assert sample.errors.on(:location_id)
251
+ assert_match(/blank/, sample.errors.on(:location_id) )
252
+ end
253
+ end
254
+
255
+ test "should require received_by_lab_on if aliquotted_on" do
256
+ assert_difference( 'Sample.count', 0 ) do
257
+ sample = create_sample(
258
+ :received_by_lab_on => nil,
259
+ :aliquotted_on => Date.yesterday
260
+ )
261
+ assert sample.errors.on(:received_by_lab_on)
262
+ assert_match(/be blank/,
263
+ sample.errors.on(:received_by_lab_on) )
264
+ end
265
+ end
266
+
267
+ test "should require aliquotted_on be after received_by_lab_on" do
268
+ assert_difference( 'Sample.count', 0 ) do
269
+ sample = create_sample(
270
+ :received_by_lab_on => Date.tomorrow,
271
+ :aliquotted_on => Date.yesterday
272
+ )
273
+ assert sample.errors.on(:aliquotted_on)
274
+ assert_match(/after received_by_lab_on/,
275
+ sample.errors.on(:aliquotted_on) )
276
+ end
277
+ end
278
+
279
+ test "should create homex outcome with sample" do
280
+ study_subject = create_hx_study_subject
281
+ assert_difference( 'Sample.count', 1 ) {
282
+ assert_difference( 'HomexOutcome.count', 1 ) {
283
+ sample = create_sample(
284
+ :study_subject => study_subject,
285
+ :project => Project['HomeExposures'] )
286
+ } }
287
+ end
288
+
289
+ test "should update homex outcome sample_outcome to sent" do
290
+ study_subject = create_hx_study_subject
291
+ assert_difference( 'OperationalEvent.count', 1 ) {
292
+ assert_difference( 'Sample.count', 1 ) {
293
+ assert_difference( 'HomexOutcome.count', 1 ) {
294
+ sample = create_sample(
295
+ :study_subject => study_subject,
296
+ :project => Project['HomeExposures'],
297
+ :sent_to_subject_on => Date.yesterday )
298
+ assert_equal SampleOutcome['sent'],
299
+ sample.study_subject.homex_outcome.sample_outcome
300
+ assert_equal sample.sent_to_subject_on,
301
+ sample.study_subject.homex_outcome.sample_outcome_on
302
+ } } }
303
+ end
304
+
305
+ test "should update homex outcome sample_outcome to received" do
306
+ study_subject = create_hx_study_subject
307
+ assert_difference( 'OperationalEvent.count', 1 ) {
308
+ assert_difference( 'Sample.count', 1 ) {
309
+ assert_difference( 'HomexOutcome.count', 1 ) {
310
+ today = Date.today
311
+ sample = create_sample(
312
+ :study_subject => study_subject,
313
+ :project => Project['HomeExposures'],
314
+ :sent_to_subject_on => ( today - 3.days ),
315
+ :collected_at => ( today - 2.days ),
316
+ :received_by_ccls_at => ( today - 1.day ) )
317
+ assert_equal SampleOutcome['received'],
318
+ sample.study_subject.homex_outcome.sample_outcome
319
+ assert_equal sample.received_by_ccls_at,
320
+ sample.study_subject.homex_outcome.sample_outcome_on
321
+ } } }
322
+ end
323
+
324
+ test "should update homex outcome sample_outcome to lab" do
325
+ study_subject = create_hx_study_subject
326
+ # This update does not create an operational event
327
+ # assert_difference( 'OperationalEvent.count', 1 ) {
328
+ assert_difference( 'Sample.count', 1 ) {
329
+ assert_difference( 'HomexOutcome.count', 1 ) {
330
+ today = Date.today
331
+ sample = create_sample(
332
+ :study_subject => study_subject,
333
+ :project => Project['HomeExposures'],
334
+ :organization => Factory(:organization),
335
+ :sent_to_subject_on => ( today - 4.days ),
336
+ :collected_at => ( today - 3.days ),
337
+ :received_by_ccls_at => ( today - 2.days ),
338
+ :sent_to_lab_on => ( today - 1.day ) )
339
+ assert !sample.new_record?, "Object was not created"
340
+ assert_equal SampleOutcome['lab'],
341
+ sample.study_subject.homex_outcome.sample_outcome
342
+ assert_equal sample.sent_to_lab_on,
343
+ sample.study_subject.homex_outcome.sample_outcome_on
344
+ } } #}
345
+ end
346
+
347
+ test "should respond to sample_type_parent" do
348
+ sample = create_sample
349
+ assert sample.respond_to? :sample_type_parent
350
+ sample_type_parent = sample.sample_type_parent
351
+ assert_not_nil sample_type_parent
352
+ assert sample_type_parent.is_a?(SampleType)
353
+ end
354
+
355
+ #protected
356
+ #
357
+ # def create_sample(options={})
358
+ # sample = Factory.build(:sample,options)
359
+ # sample.save
360
+ # sample
361
+ # end
362
+
363
+ end