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,23 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::FollowUpTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_initially_belong_to(
7
+ :section,
8
+ :enrollment,
9
+ :follow_up_type)
10
+
11
+ test "explicit Factory follow_up test" do
12
+ assert_difference('FollowUpType.count',1) {
13
+ assert_difference('Enrollment.count',2) { # again, creates subject, which creates ccls enrollment
14
+ assert_difference('Section.count',1) {
15
+ assert_difference('FollowUp.count',1) {
16
+ follow_up = Factory(:follow_up)
17
+ assert_not_nil follow_up.section
18
+ assert_not_nil follow_up.enrollment
19
+ assert_not_nil follow_up.follow_up_type
20
+ } } } }
21
+ end
22
+
23
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::FollowUpTypeTest < 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(:follow_ups)
10
+ assert_should_not_require_attributes( :position )
11
+ # assert_should_require_attribute_length( :event_category, :in => 4..250 )
12
+
13
+ test "explicit Factory follow_up_type test" do
14
+ assert_difference('FollowUpType.count',1) {
15
+ follow_up_type = Factory(:follow_up_type)
16
+ assert_match /Key\d*/, follow_up_type.key
17
+ assert_match /Desc\d*/, follow_up_type.description
18
+ }
19
+ end
20
+
21
+ test "should return description as to_s" do
22
+ follow_up_type = create_follow_up_type
23
+ assert_equal follow_up_type.description, "#{follow_up_type}"
24
+ end
25
+
26
+ #protected
27
+ #
28
+ # def create_follow_up_type(options={})
29
+ # follow_up_type = Factory.build(:follow_up_type,options)
30
+ # follow_up_type.save
31
+ # follow_up_type
32
+ # end
33
+
34
+ end
@@ -0,0 +1,153 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::GiftCardSearchTest < ActiveSupport::TestCase
4
+
5
+ # test "should return GiftCardSearch" do
6
+ # assert GiftCardSearch().is_a?(GiftCardSearch)
7
+ # end
8
+
9
+ test "should respond to search" do
10
+ assert GiftCard.respond_to?(:search)
11
+ end
12
+
13
+ test "should return Array" do
14
+ gift_cards = GiftCard.search()
15
+ assert gift_cards.is_a?(Array)
16
+ end
17
+
18
+ test "should include gift_card" do
19
+ gift_card = create_gift_card
20
+ # there are already about 40 in the fixtures
21
+ # so we need to get more than that to include the last one.
22
+ gift_cards = GiftCard.search(:per_page => 50)
23
+ assert gift_cards.include?(gift_card)
24
+ end
25
+
26
+ test "should include gift_card without pagination" do
27
+ gift_card = create_gift_card
28
+ gift_cards = GiftCard.search(:paginate => false)
29
+ assert gift_cards.include?(gift_card)
30
+ end
31
+
32
+ test "should NOT order by bogus column with dir" do
33
+ GiftCard.destroy_all
34
+ g1,g2,g3 = create_gift_cards(3)
35
+ gift_cards = GiftCard.search(
36
+ :order => 'whatever', :dir => 'asc')
37
+ assert_equal [g1,g2,g3], gift_cards
38
+ end
39
+
40
+ test "should NOT order by bogus column" do
41
+ GiftCard.destroy_all
42
+ g1,g2,g3 = create_gift_cards(3)
43
+ gift_cards = GiftCard.search(:order => 'whatever')
44
+ assert_equal [g1,g2,g3], gift_cards
45
+ end
46
+
47
+ test "should order by id asc by default" do
48
+ GiftCard.destroy_all
49
+ g1,g2,g3 = create_gift_cards_with_childids(9,3,6)
50
+ gift_cards = GiftCard.search(
51
+ :order => 'id')
52
+ assert_equal [g1,g2,g3], gift_cards
53
+ end
54
+
55
+ test "should order by id asc" do
56
+ GiftCard.destroy_all
57
+ g1,g2,g3 = create_gift_cards_with_childids(9,3,6)
58
+ gift_cards = GiftCard.search(
59
+ :order => 'id', :dir => 'asc')
60
+ assert_equal [g1,g2,g3], gift_cards
61
+ end
62
+
63
+ test "should order by id desc" do
64
+ GiftCard.destroy_all
65
+ g1,g2,g3 = create_gift_cards_with_childids(9,3,6)
66
+ gift_cards = GiftCard.search(
67
+ :order => 'id', :dir => 'desc')
68
+ assert_equal [g3,g2,g1], gift_cards
69
+ end
70
+
71
+ test "should include gift_card by q first_name" do
72
+ g1,g2 = create_gift_cards_with_first_names('Michael','Bob')
73
+ gift_cards = GiftCard.search(:q => 'mi ch ha')
74
+ assert gift_cards.include?(g1)
75
+ assert !gift_cards.include?(g2)
76
+ end
77
+
78
+ test "should include gift_card by q last_name" do
79
+ g1,g2 = create_gift_cards_with_last_names('Michael','Bob')
80
+ gift_cards = GiftCard.search(:q => 'cha ael')
81
+ assert gift_cards.include?(g1)
82
+ assert !gift_cards.include?(g2)
83
+ end
84
+
85
+ test "should include gift_card by q childid" do
86
+ g1,g2 = create_gift_cards_with_childids(999999,'1')
87
+ assert_equal 999999, g1.study_subject.childid
88
+ gift_cards = GiftCard.search(:q => g1.study_subject.childid)
89
+ assert gift_cards.include?(g1)
90
+ assert !gift_cards.include?(g2)
91
+ end
92
+
93
+ test "should include gift_card by q patid" do
94
+ g1,g2 = create_gift_cards_with_patids(999999,'1')
95
+ gift_cards = GiftCard.search(:q => g1.study_subject.patid)
96
+ assert gift_cards.include?(g1)
97
+ assert !gift_cards.include?(g2)
98
+ end
99
+
100
+ test "should include gift_card by q number" do
101
+ g1,g2 = create_gift_cards_with_numbers('9999','1111')
102
+ gift_cards = GiftCard.search(:q => g1.number)
103
+ assert gift_cards.include?(g1)
104
+ assert !gift_cards.include?(g2)
105
+ end
106
+
107
+ protected
108
+
109
+ def create_gift_card(options={})
110
+ gift_card = Factory.build(:gift_card,options)
111
+ gift_card.save
112
+ gift_card
113
+ end
114
+
115
+ def create_gift_cards(count=0,options={})
116
+ gift_cards = []
117
+ count.times{ gift_cards.push(create_gift_card(options)) }
118
+ return gift_cards
119
+ end
120
+
121
+ def create_gift_card_with_first_name(first_name)
122
+ study_subject = create_study_subject_with_first_name(first_name)
123
+ gift_card = create_gift_card
124
+ study_subject.gift_cards << gift_card
125
+ gift_card
126
+ end
127
+
128
+ def create_gift_card_with_last_name(last_name)
129
+ study_subject = create_study_subject_with_last_name(last_name)
130
+ gift_card = create_gift_card
131
+ study_subject.gift_cards << gift_card
132
+ gift_card
133
+ end
134
+
135
+ def create_gift_card_with_childid(childid)
136
+ study_subject = create_study_subject_with_childid(childid)
137
+ gift_card = create_gift_card
138
+ study_subject.gift_cards << gift_card
139
+ gift_card
140
+ end
141
+
142
+ def create_gift_card_with_patid(patid)
143
+ study_subject = create_study_subject_with_patid(patid)
144
+ gift_card = create_gift_card
145
+ study_subject.gift_cards << gift_card
146
+ gift_card
147
+ end
148
+
149
+ def create_gift_card_with_number(number)
150
+ create_gift_card(:number => number)
151
+ end
152
+
153
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::GiftCardTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_belong_to(:study_subject, :project)
7
+ assert_should_protect( :study_subject_id, :study_subject )
8
+ assert_should_require_attributes(:number)
9
+ assert_should_require_unique_attributes(:number)
10
+ assert_should_not_require_attributes( :study_subject_id,
11
+ :project_id,
12
+ :issued_on,
13
+ :expiration,
14
+ :vendor )
15
+ assert_should_require_attribute_length( :expiration,
16
+ :vendor,
17
+ :number,
18
+ :maximum => 250 )
19
+
20
+ test "explicit Factory gift_card test" do
21
+ assert_difference('GiftCard.count',1) {
22
+ gift_card = Factory(:gift_card)
23
+ assert_match /\d*/, gift_card.number
24
+ }
25
+ end
26
+
27
+ test "should return number as to_s" do
28
+ gift_card = create_gift_card
29
+ assert_equal gift_card.number, "#{gift_card}"
30
+ end
31
+
32
+ #protected
33
+ #
34
+ # def create_gift_card(options={})
35
+ # gift_card = Factory.build(:gift_card,options)
36
+ # gift_card.save
37
+ # gift_card
38
+ # end
39
+
40
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::HomeExposureResponseTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_initially_belong_to(:study_subject)
7
+ assert_should_protect( :study_subject_id, :study_subject )
8
+ assert_should_require_attribute_length( :additional_comments, :maximum => 65000 )
9
+
10
+ # not working
11
+ # assert_should_require_unique_attribute(:study_subject_id)
12
+
13
+ test "explicit Factory home_exposure_response test" do
14
+ assert_difference('StudySubject.count',1) {
15
+ assert_difference('HomeExposureResponse.count',1) {
16
+ home_exposure_response = Factory(:home_exposure_response)
17
+ assert_not_nil home_exposure_response.study_subject
18
+ } }
19
+ end
20
+
21
+ # test "should require study_subject" do
22
+ # assert_difference( "HomeExposureResponse.count", 0 ) do
23
+ # home_exposure_response = create_home_exposure_response( :study_subject => nil)
24
+ # assert !home_exposure_response.errors.on(:study_subject)
25
+ # assert home_exposure_response.errors.on_attr_and_type?(:study_subject_id, :blank)
26
+ # end
27
+ # end
28
+ #
29
+ # test "should require valid study_subject" do
30
+ # assert_difference( "HomeExposureResponse.count", 0 ) do
31
+ # home_exposure_response = create_home_exposure_response( :study_subject_id => 0)
32
+ # assert !home_exposure_response.errors.on(:study_subject_id)
33
+ # assert home_exposure_response.errors.on_attr_and_type?(:study_subject,:blank)
34
+ # end
35
+ # end
36
+
37
+ test "should require unique study_subject_id" do
38
+ o = create_home_exposure_response
39
+ assert_no_difference "HomeExposureResponse.count" do
40
+ home_exposure_response = create_home_exposure_response(
41
+ :study_subject => o.study_subject)
42
+ assert home_exposure_response.errors.on_attr_and_type?(:study_subject_id, :taken)
43
+ end
44
+ end
45
+
46
+ test "should return array of fields" do
47
+ fields = HomeExposureResponse.fields
48
+ assert fields.is_a?(Array)
49
+ assert fields.length > 100
50
+ assert fields.first.is_a?(Hash)
51
+ end
52
+
53
+ test "should return array of db_field_names" do
54
+ db_field_names = HomeExposureResponse.db_field_names
55
+ assert db_field_names.is_a?(Array)
56
+ assert db_field_names.length > 100
57
+ assert db_field_names.first.is_a?(String)
58
+ end
59
+
60
+ # test "should return array of field_names" do
61
+ # field_names = HomeExposureResponse.field_names
62
+ # assert field_names.is_a?(Array)
63
+ # assert field_names.length > 100
64
+ # end
65
+
66
+ # temporary? It's been here a while.
67
+ # test "should return the same array for field_names and db_field_names" do
68
+ # db_field_names = HomeExposureResponse.db_field_names
69
+ # field_names = HomeExposureResponse.field_names
70
+ # assert_equal field_names, db_field_names
71
+ # end
72
+
73
+ assert_should_not_require_attributes( *HomeExposureResponse.db_field_names )
74
+
75
+ #protected
76
+ #
77
+ # def create_home_exposure_response(options={})
78
+ # home_exposure_response = Factory.build(:home_exposure_response,options)
79
+ # home_exposure_response.save
80
+ # home_exposure_response
81
+ # end
82
+
83
+ end
@@ -0,0 +1,199 @@
1
+ require 'test_helper'
2
+
3
+ class Ccls::HomexOutcomeTest < ActiveSupport::TestCase
4
+
5
+ assert_should_create_default_object
6
+ assert_should_act_as_list
7
+ assert_should_belong_to(
8
+ :study_subject,
9
+ :sample_outcome,
10
+ :interview_outcome )
11
+ assert_should_protect( :study_subject_id, :study_subject )
12
+ assert_requires_complete_date(
13
+ :interview_outcome_on,
14
+ :sample_outcome_on )
15
+ assert_should_not_require_attributes(
16
+ :position,
17
+ :study_subject_id,
18
+ :sample_outcome_id,
19
+ :sample_outcome_on,
20
+ :interview_outcome_id,
21
+ :interview_outcome_on )
22
+
23
+ # TODO Need to add something to allow_nil => true
24
+ # assert_should_require_unique_attribute(:study_subject_id)
25
+
26
+ test "explicit Factory homex_outcome test" do
27
+ assert_difference('HomexOutcome.count',1) {
28
+ homex_outcome = Factory(:homex_outcome)
29
+ assert_nil homex_outcome.sample_outcome
30
+ assert_not_nil homex_outcome.sample_outcome_on # because of SampleOutcome test
31
+ assert_nil homex_outcome.interview_outcome
32
+ assert_not_nil homex_outcome.interview_outcome_on # because of InterviewOutcome test
33
+ }
34
+ end
35
+
36
+ #
37
+ # study_subject uses accepts_attributes_for :pii
38
+ # so the pii can't require study_subject_id on create
39
+ # or this test fails.
40
+ #
41
+ # test "should require study_subject_id on update" do
42
+ # assert_difference( "HomexOutcome.count", 1 ) do
43
+ # homex_outcome = create_homex_outcome
44
+ # homex_outcome.reload.update_attributes(:updated_at => Time.now)
45
+ # assert !homex_outcome.errors.on(:study_subject)
46
+ # assert homex_outcome.errors.on_attr_and_type?(:study_subject_id,:blank)
47
+ # end
48
+ # end
49
+
50
+ # validate on foreign key rather than association so error shows up correctly in view.
51
+ # test "should require valid study_subject" do
52
+ # end
53
+
54
+ test "should require unique study_subject_id" do
55
+ study_subject = Factory(:study_subject)
56
+ create_homex_outcome(:study_subject => study_subject)
57
+ assert_difference( "HomexOutcome.count", 0 ) do
58
+ homex_outcome = create_homex_outcome(:study_subject => study_subject)
59
+ assert homex_outcome.errors.on(:study_subject_id)
60
+ end
61
+ end
62
+
63
+ test "should require interview_outcome_on if interview_outcome_id?" do
64
+ assert_difference( "HomexOutcome.count", 0 ) do
65
+ homex_outcome = create_homex_outcome(
66
+ :interview_outcome_on => nil,
67
+ :interview_outcome_id => InterviewOutcome.first.id)
68
+ assert homex_outcome.errors.on(:interview_outcome_on)
69
+ end
70
+ end
71
+
72
+ test "should require sample_outcome_on if sample_outcome_id?" do
73
+ assert_difference( "HomexOutcome.count", 0 ) do
74
+ homex_outcome = create_homex_outcome(
75
+ :sample_outcome_on => nil,
76
+ :sample_outcome_id => SampleOutcome.first.id)
77
+ assert homex_outcome.errors.on(:sample_outcome_on)
78
+ end
79
+ end
80
+
81
+ test "should create operational event when interview scheduled" do
82
+ homex_outcome = create_complete_homex_outcome
83
+ # arbitrary past date
84
+ past_date = Date.parse('Jan 15 2003')
85
+ assert_difference('OperationalEvent.count',1) do
86
+ homex_outcome.update_attributes(
87
+ :interview_outcome_on => past_date,
88
+ :interview_outcome => InterviewOutcome['scheduled'])
89
+ end
90
+ oe = OperationalEvent.last
91
+ assert_equal 'scheduled', oe.operational_event_type.key
92
+ assert_equal past_date, oe.occurred_on
93
+ assert_equal homex_outcome.study_subject_id, oe.enrollment.study_subject_id
94
+ end
95
+
96
+ test "should create operational event when interview completed" do
97
+ homex_outcome = create_complete_homex_outcome
98
+ # arbitrary past date
99
+ past_date = Date.parse('Jan 15 2003')
100
+ assert_difference('OperationalEvent.count',1) do
101
+ homex_outcome.update_attributes(
102
+ :interview_outcome_on => past_date,
103
+ :interview_outcome => InterviewOutcome['complete'])
104
+ end
105
+ oe = OperationalEvent.last
106
+ assert_equal 'iv_complete', oe.operational_event_type.key
107
+ assert_equal past_date, oe.occurred_on
108
+ assert_equal homex_outcome.study_subject_id, oe.enrollment.study_subject_id
109
+ end
110
+
111
+ test "should raise NoHomeExposureEnrollment on create_interview_outcome_update" <<
112
+ " if no enrollment in HomeExposures" do
113
+ study_subject = Factory(:study_subject)
114
+ homex_outcome = Factory(:homex_outcome,:study_subject => study_subject)
115
+ assert_nil study_subject.enrollments.find_by_project_id(Project['HomeExposures'].id)
116
+ assert_raises(HomexOutcome::NoHomeExposureEnrollment){
117
+ homex_outcome.update_attributes(
118
+ :interview_outcome_on => Date.parse('Jan 15 2003'),
119
+ :interview_outcome => InterviewOutcome['complete'])
120
+ }
121
+ end
122
+
123
+ test "should create operational event when sample kit sent" do
124
+ homex_outcome = create_complete_homex_outcome
125
+ # arbitrary past date
126
+ past_date = Date.parse('Jan 15 2003')
127
+ assert_difference('OperationalEvent.count',1) do
128
+ homex_outcome.update_attributes(
129
+ :sample_outcome_on => past_date,
130
+ :sample_outcome => SampleOutcome['sent'])
131
+ end
132
+ oe = OperationalEvent.last
133
+ assert_equal 'kit_sent', oe.operational_event_type.key
134
+ assert_equal past_date, oe.occurred_on
135
+ assert_equal homex_outcome.study_subject_id, oe.enrollment.study_subject_id
136
+ end
137
+
138
+ test "should create operational event when sample received" do
139
+ homex_outcome = create_complete_homex_outcome
140
+ # arbitrary past date
141
+ past_date = Date.parse('Jan 15 2003')
142
+ assert_difference('OperationalEvent.count',1) do
143
+ homex_outcome.update_attributes(
144
+ :sample_outcome_on => past_date,
145
+ :sample_outcome => SampleOutcome['received'])
146
+ end
147
+ oe = OperationalEvent.last
148
+ assert_equal 'sample_received', oe.operational_event_type.key
149
+ assert_equal past_date, oe.occurred_on
150
+ assert_equal homex_outcome.study_subject_id, oe.enrollment.study_subject_id
151
+ end
152
+
153
+ test "should create operational event when sample complete" do
154
+ homex_outcome = create_complete_homex_outcome
155
+ # arbitrary past date
156
+ past_date = Date.parse('Jan 15 2003')
157
+ assert_difference('OperationalEvent.count',1) do
158
+ homex_outcome.update_attributes(
159
+ :sample_outcome_on => past_date,
160
+ :sample_outcome => SampleOutcome['complete'])
161
+ end
162
+ oe = OperationalEvent.last
163
+ assert_equal 'sample_complete', oe.operational_event_type.key
164
+ assert_equal past_date, oe.occurred_on
165
+ assert_equal homex_outcome.study_subject_id, oe.enrollment.study_subject_id
166
+ end
167
+
168
+ test "should raise NoHomeExposureEnrollment on create_sample_outcome_update" <<
169
+ " if no enrollment in HomeExposures" do
170
+ study_subject = Factory(:study_subject)
171
+ homex_outcome = Factory(:homex_outcome,:study_subject => study_subject)
172
+ assert_nil study_subject.enrollments.find_by_project_id(Project['HomeExposures'].id)
173
+ assert_raises(HomexOutcome::NoHomeExposureEnrollment){
174
+ homex_outcome.update_attributes(
175
+ :sample_outcome_on => Date.parse('Jan 15 2003'),
176
+ :sample_outcome => SampleOutcome['complete'])
177
+ }
178
+ end
179
+
180
+ protected
181
+
182
+ # def create_homex_outcome(options={})
183
+ # homex_outcome = Factory.build(:homex_outcome,options)
184
+ # homex_outcome.save
185
+ # homex_outcome
186
+ # end
187
+
188
+ def create_complete_homex_outcome(options={})
189
+ s = Factory(:study_subject,options[:study_subject]||{})
190
+ p = Project.find_or_create_by_key('HomeExposures')
191
+ Factory(:enrollment, :study_subject => s, :project => p )
192
+ h = create_homex_outcome(
193
+ (options[:homex_outcome]||{}).merge(:study_subject => s,
194
+ :interview_outcome_on => nil,
195
+ :sample_outcome_on => nil))
196
+ h
197
+ end
198
+
199
+ end