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,276 @@
1
+ module Ccls::FactoryTestHelper
2
+
3
+ #../ccls_engine/test/unit/ccls/study_subject_test.rb
4
+ #../homex/test/functional/followup/study_subjects_controller_test.rb
5
+ #../homex/test/functional/home_exposure_responses_controller_test.rb
6
+ #../homex/test/functional/interview/study_subjects_controller_test.rb
7
+ #../homex/test/functional/sample/study_subjects_controller_test.rb
8
+ #../homex/test/functional/study_subjects_controller_test.rb
9
+ def create_home_exposure_with_study_subject(options={})
10
+ study_subject = project = nil
11
+ unless options[:patient].nil?
12
+ options[:study_subject] ||= {}
13
+ options[:study_subject][:subject_type] = SubjectType['Case']
14
+ end
15
+ assert_difference('StudySubject.count',1) {
16
+ study_subject = Factory(:study_subject,options[:study_subject]||{})
17
+ }
18
+ project = Project.find_or_create_by_key('HomeExposures')
19
+ assert_not_nil project
20
+ assert_difference('StudySubject.count',0) {
21
+ assert_difference('Enrollment.count',1) {
22
+ Factory(:enrollment, (options[:enrollment]||{}).merge(
23
+ :study_subject => study_subject, :project => project ))
24
+ } }
25
+ unless options[:patient].nil?
26
+ assert_difference('StudySubject.count',0) {
27
+ assert_difference('Patient.count',1) {
28
+ Factory(:patient, :study_subject => study_subject )
29
+ } }
30
+ end
31
+ study_subject
32
+ end
33
+
34
+ #../ccls_engine/test/unit/ccls/addressing_test.rb
35
+ #../ccls_engine/test/unit/ccls/interview_test.rb
36
+ #../ccls_engine/test/unit/ccls/sample_test.rb
37
+ #../ccls_engine/test/unit/ccls/study_subject_search_test.rb
38
+ #../homex/test/functional/addressings_controller_test.rb
39
+ #../homex/test/functional/events_controller_test.rb
40
+ #../homex/test/functional/followup/study_subjects_controller_test.rb
41
+ #../homex/test/functional/interview/study_subjects_controller_test.rb
42
+ alias_method :create_hx_study_subject,
43
+ :create_home_exposure_with_study_subject
44
+
45
+
46
+ #../ccls_engine/test/unit/ccls/addressing_test.rb
47
+ #../homex/test/functional/addressings_controller_test.rb
48
+ def create_eligible_hx_study_subject()
49
+ study_subject = nil
50
+ assert_nil study_subject
51
+ assert_difference('Enrollment.count',2) { # homex and auto-created ccls
52
+ assert_difference('StudySubject.count',1) {
53
+ study_subject = create_hx_study_subject(:enrollment => {
54
+ :is_eligible => YNDK[:yes] })
55
+ } }
56
+ assert_not_nil study_subject
57
+ assert_study_subject_is_eligible(study_subject)
58
+ study_subject
59
+ end
60
+
61
+ #../ccls_engine/test/unit/ccls/study_subject_interviews_test.rb
62
+ #../homex/test/functional/interview/study_subjects_controller_test.rb
63
+ def create_hx_interview_study_subject(options={})
64
+ study_subject = create_hx_study_subject
65
+ instrument = Factory(:instrument,
66
+ :project => Project.find_or_create_by_key('HomeExposures'))
67
+ instrument_version = Factory(:instrument_version,
68
+ :instrument => instrument)
69
+ interview = Factory(:interview,
70
+ :study_subject => study_subject,
71
+ :instrument_version => instrument_version)
72
+ study_subject
73
+ end
74
+
75
+ def create_study_subjects(count=0,options={})
76
+ study_subjects = []
77
+ count.times{ study_subjects.push(create_study_subject(options)) }
78
+ return study_subjects
79
+ end
80
+
81
+ def create_study_subjects_with_recruitment_priorities(*priorities)
82
+ project = nil
83
+ assert_difference('Project.count',1) {
84
+ project = Factory(:project)
85
+ }
86
+ study_subjects = priorities.collect do |priority|
87
+ study_subject = nil
88
+ assert_difference('Enrollment.count',1){ # auto-created ccls enrollment
89
+ assert_difference('StudySubject.count',1) {
90
+ study_subject = create_study_subject
91
+ } }
92
+ assert_difference('Enrollment.count',1){
93
+ Factory(:enrollment, :project => project,
94
+ :study_subject => study_subject,
95
+ :recruitment_priority => priority)
96
+ }
97
+ study_subject
98
+ end
99
+ return [project,*study_subjects]
100
+ end
101
+
102
+ def create_study_subject_with_gift_card_number(gift_card_number)
103
+ study_subject = create_study_subject
104
+ Factory(:gift_card,
105
+ :study_subject => study_subject,
106
+ :number => gift_card_number )
107
+ study_subject
108
+ end
109
+
110
+ def create_study_subjects_with_races(count=0,options={})
111
+ study_subjects = create_study_subjects(count)
112
+ study_subjects.each{|s|s.races << Factory(:race)}
113
+ study_subjects
114
+ end
115
+
116
+ def create_study_subject_with_childid(childid)
117
+ StudySubject.any_instance.stubs(:get_next_childid).returns(childid)
118
+ study_subject = Factory(:study_subject)
119
+ StudySubject.any_instance.unstub(:get_next_childid)
120
+ assert_not_nil study_subject.childid
121
+ assert_equal childid.to_s, study_subject.childid.to_s
122
+ study_subject
123
+ end
124
+
125
+ def three_study_subjects_with_childid
126
+ create_study_subjects_with_childids(9,3,6)
127
+ end
128
+
129
+ def create_study_subject_with_patid(patid)
130
+ study_subject = Factory(:study_subject) #not case so shouldn't create patid
131
+ assert_nil study_subject.patid
132
+ study_subject.update_attribute(:patid, patid)
133
+ assert_not_nil study_subject.patid
134
+ assert_equal patid.to_s, study_subject.patid.to_s
135
+ study_subject
136
+ end
137
+ alias_method :create_study_subject_with_studyid,
138
+ :create_study_subject_with_patid
139
+
140
+ def three_study_subjects_with_patid
141
+ create_study_subjects_with_patids(9,3,6)
142
+ end
143
+ alias_method :three_study_subjects_with_studyid,
144
+ :three_study_subjects_with_patid
145
+
146
+ def create_study_subject_with_last_name(last_name)
147
+ create_study_subject( :last_name => last_name )
148
+ end
149
+
150
+ def three_study_subjects_with_last_name
151
+ create_study_subjects_with_last_names('9','3','6')
152
+ end
153
+
154
+ def create_study_subject_with_first_name(first_name)
155
+ create_study_subject( :first_name => first_name )
156
+ end
157
+
158
+ def three_study_subjects_with_first_name
159
+ create_study_subjects_with_first_names('9','3','6')
160
+ end
161
+
162
+ def create_study_subject_with_dob(dob)
163
+ # Time.parse? Why not Date? Time.parse parses better.
164
+ create_study_subject( :dob => Time.parse(dob) )
165
+ end
166
+
167
+ def three_study_subjects_with_dob
168
+ create_study_subjects_with_dobs(
169
+ '12/31/2005','12/31/2001','12/31/2003')
170
+ end
171
+
172
+ #
173
+ # three_study_subjects_with_* methods called from StudySubjectSearchTest
174
+ #
175
+ def three_study_subjects_with_sample_outcome_on
176
+ create_study_subjects_with_sample_outcome_ons(
177
+ '12/31/2005','12/31/2001','12/31/2003')
178
+ end
179
+
180
+ def three_study_subjects_with_sample_outcome
181
+ create_study_subjects_with_sample_outcomes('9','3','6')
182
+ end
183
+
184
+ def three_study_subjects_with_interview_outcome_on
185
+ create_study_subjects_with_interview_outcome_ons(
186
+ '12/31/2005','12/31/2001','12/31/2003')
187
+ end
188
+
189
+ # def three_study_subjects_with_sent_to_subject_on
190
+ # create_study_subjects_with_sent_to_subject_on(
191
+ # '12/31/2005','12/31/2001','12/31/2003')
192
+ # end
193
+ #
194
+ # def three_study_subjects_with_received_by_ccls_at
195
+ # create_study_subjects_with_received_by_ccls_at(
196
+ # '12/31/2005','12/31/2001','12/31/2003')
197
+ # end
198
+
199
+ def create_case_study_subject_with_patid(patid)
200
+ StudySubject.any_instance.stubs(:get_next_patid).returns(patid)
201
+ study_subject = create_case_study_subject
202
+ StudySubject.any_instance.unstub(:get_next_patid)
203
+ study_subject.reload
204
+ end
205
+
206
+ #########
207
+
208
+ def method_missing_with_pluralization(symb,*args, &block)
209
+ method_name = symb.to_s
210
+ if method_name =~ /^create_(.*)_with_(.*)$/
211
+ model = $1.singularize
212
+ attribute = $2.singularize
213
+ args.collect do |arg|
214
+ send("create_#{model}_with_#{attribute}",arg)
215
+ end
216
+ else
217
+ method_missing_without_pluralization(symb, *args, &block)
218
+ end
219
+ end
220
+
221
+ def self.included(base)
222
+ base.alias_method_chain( :method_missing, :pluralization
223
+ ) unless base.respond_to?(:method_missing_without_pluralization)
224
+ end
225
+
226
+
227
+ protected # NOT called from the outside
228
+
229
+ def create_study_subject_with_sample_outcome_on(date)
230
+ s = create_hx_study_subject
231
+ s.update_attributes(
232
+ :homex_outcome_attributes => Factory.attributes_for(:homex_outcome,
233
+ :sample_outcome_on => date) )
234
+ s
235
+ end
236
+
237
+ def create_study_subject_with_sample_outcome(outcome)
238
+ s = create_hx_study_subject
239
+ s.update_attributes(
240
+ :homex_outcome_attributes => Factory.attributes_for(:homex_outcome,
241
+ :sample_outcome_id => outcome) )
242
+ s
243
+ end
244
+
245
+ def create_study_subject_with_interview_outcome_on(date)
246
+ create_hx_study_subject(:study_subject => {
247
+ :homex_outcome_attributes => Factory.attributes_for(:homex_outcome,
248
+ :interview_outcome_on => date ) })
249
+ end
250
+
251
+ # # only called through pluralization
252
+ # def create_study_subject_with_sent_to_subject_on(date)
253
+ # study_subject = create_hx_study_subject
254
+ # Factory(:sample,
255
+ # :study_subject => study_subject,
256
+ # :sent_to_subject_on => Date.parse(date)
257
+ # )
258
+ # study_subject
259
+ # end
260
+ #
261
+ # # only called through pluralization
262
+ # def create_study_subject_with_received_by_ccls_at(date)
263
+ # study_subject = create_hx_study_subject
264
+ # Factory(:sample,
265
+ # :study_subject => study_subject,
266
+ # :sent_to_subject_on => (Date.parse(date) - 10.days),
267
+ ## :collected_at => (Time.zone.parse(date) - 5.days),
268
+ ## :received_by_ccls_at => Time.zone.parse(date)
269
+ # :collected_at => (Date.parse(date) - 5.days),
270
+ # :received_by_ccls_at => Date.parse(date)
271
+ # )
272
+ # study_subject
273
+ # end
274
+
275
+ end
276
+ ActiveSupport::TestCase.send(:include, Ccls::FactoryTestHelper)
@@ -0,0 +1,112 @@
1
+ module Ccls::Helper
2
+
3
+ def sort_up_image
4
+ "#{Rails.root}/public/images/sort_up.png"
5
+ end
6
+
7
+ def sort_down_image
8
+ "#{Rails.root}/public/images/sort_down.png"
9
+ end
10
+
11
+ # &uarr; and &darr;
12
+ def sort_link(column,text=nil)
13
+ # make local copy so mods to muck up real params which
14
+ # may still be references elsewhere.
15
+ local_params = params.dup
16
+
17
+ #
18
+ # May want to NOT flip dir for other columns. Only the current order.
19
+ # Will wait until someone else makes the suggestion.
20
+ #
21
+ order = column.to_s.downcase.gsub(/\s+/,'_')
22
+ dir = ( local_params[:dir] && local_params[:dir] == 'asc' ) ? 'desc' : 'asc'
23
+
24
+ local_params[:page] = nil
25
+ link_text = text||column
26
+ classes = ['sortable',order]
27
+ arrow = ''
28
+ if local_params[:order] && local_params[:order] == order
29
+ classes.push('sorted')
30
+ arrow = if dir == 'desc'
31
+ if File.exists? sort_down_image
32
+ image_tag( File.basename(sort_down_image), :class => 'down arrow')
33
+ else
34
+ "<span class='down arrow'>&darr;</span>"
35
+ end
36
+ else
37
+ if File.exists? sort_up_image
38
+ image_tag( File.basename(sort_up_image), :class => 'up arrow')
39
+ else
40
+ "<span class='up arrow'>&uarr;</span>"
41
+ end
42
+ end
43
+ end
44
+ s = "<div class='#{classes.join(' ')}'>"
45
+ s << link_to(link_text,local_params.merge(:order => order,:dir => dir))
46
+ s << arrow unless arrow.blank?
47
+ s << "</div>"
48
+ s
49
+ end
50
+
51
+ def user_roles
52
+ s = ''
53
+ if current_user.may_administrate?
54
+ s << "<ul>"
55
+ @roles.each do |role|
56
+ s << "<li>"
57
+ if @user.role_names.include?(role.name)
58
+ s << link_to( "Remove user role of '#{role.name}'",
59
+ user_role_path(@user,role.name),
60
+ :method => :delete )
61
+ else
62
+ s << link_to( "Assign user role of '#{role.name}'",
63
+ user_role_path(@user,role.name),
64
+ :method => :put )
65
+ end
66
+ s << "</li>\n"
67
+ end
68
+ s << "</ul>\n"
69
+ end
70
+ s
71
+ end
72
+
73
+ # Used to replace the _id_bar partial
74
+ def subject_id_bar(study_subject,&block)
75
+ stylesheets('study_subject_id_bar')
76
+ content_for :main do
77
+ "<div id='id_bar'>\n" <<
78
+ "<div class='childid'>\n" <<
79
+ "<span>ChildID:</span>\n" <<
80
+ "<span>#{study_subject.try(:childid)}</span>\n" <<
81
+ "</div><!-- class='childid' -->\n" <<
82
+ "<div class='studyid'>\n" <<
83
+ "<span>StudyID:</span>\n" <<
84
+ "<span>#{study_subject.try(:studyid)}</span>\n" <<
85
+ "</div><!-- class='studyid' -->\n" <<
86
+ "<div class='full_name'>\n" <<
87
+ "<span>#{study_subject.full_name}</span>\n" <<
88
+ "</div><!-- class='full_name' -->\n" <<
89
+ "<div class='controls'>\n" <<
90
+ @content_for_id_bar.to_s <<
91
+ ((block_given?)?yield: '') <<
92
+ "</div><!-- class='controls' -->\n" <<
93
+ "</div><!-- id='id_bar' -->\n"
94
+ end
95
+
96
+ content_for :main do
97
+ "<div id='do_not_contact'>\n" <<
98
+ "Study Subject requests no further contact with Study.\n" <<
99
+ "</div>\n"
100
+ end if study_subject.try(:do_not_contact?)
101
+ end # id_bar_for
102
+ alias_method :study_subject_id_bar, :subject_id_bar
103
+
104
+ # Just a simple method to wrap the passed text in a span
105
+ # with class='required'
106
+ def required(text)
107
+ "<span class='required'>#{text}</span>"
108
+ end
109
+ alias_method :req, :required
110
+
111
+ end
112
+ ActionView::Base.send(:include, Ccls::Helper)
@@ -0,0 +1,121 @@
1
+ module Ccls::IcfMasterTrackerUpdateTestHelper
2
+
3
+ def create_test_file_and_icf_master_tracker_update(options={})
4
+ create_icf_master_tracker_update_test_file(options)
5
+ icf_master_tracker_update = create_icf_master_tracker_update_with_file
6
+ end
7
+
8
+ def create_icf_master_tracker_update_with_file
9
+ icf_master_tracker_update = Factory(:icf_master_tracker_update,
10
+ :csv_file => File.open(csv_test_file_name) )
11
+ assert_not_nil icf_master_tracker_update.csv_file_file_name
12
+ icf_master_tracker_update
13
+ end
14
+
15
+ def cleanup_icf_master_tracker_update_and_test_file(icf_master_tracker_update=nil)
16
+ if icf_master_tracker_update
17
+ icf_master_tracker_update_file = icf_master_tracker_update.csv_file.path
18
+ # explicit destroy to remove attachment
19
+ icf_master_tracker_update.destroy
20
+ unless icf_master_tracker_update_file.blank?
21
+ assert !File.exists?(icf_master_tracker_update_file)
22
+ end
23
+ if File.exists?("test/icf_master_tracker_update/#{icf_master_tracker_update.id}") &&
24
+ File.directory?("test/icf_master_tracker_update/#{icf_master_tracker_update.id}")
25
+ Dir.delete("test/icf_master_tracker_update/#{icf_master_tracker_update.id}")
26
+ end
27
+ end
28
+ if File.exists?(csv_test_file_name)
29
+ # explicit delete to remove test file
30
+ File.delete(csv_test_file_name)
31
+ end
32
+ assert !File.exists?(csv_test_file_name)
33
+ end
34
+
35
+ def create_case_for_icf_master_tracker_update
36
+ icf_master_id = Factory(:icf_master_id,:icf_master_id => '1234FAKE')
37
+ study_subject = Factory(:complete_case_study_subject)
38
+ study_subject.assign_icf_master_id
39
+ assert_equal '1234FAKE', study_subject.icf_master_id
40
+ study_subject
41
+ end
42
+
43
+ def csv_file_header_array
44
+ # ["Masterid","Motherid","Record_Owner","Datereceived","Lastatt","Lastdisp","Currphone","Vacauthrecd","Recollect","Needpreincentive","Active_Phone","Recordsentformatching","Recordreceivedfrommatching","Sentpreincentive","Releasedtocati","Confirmedcaticontact","Refused","Deceasednotification","Eligible","Confirmationpacketsent","Catiprotocolexhausted","Newphonenumreleasedtocati","Pleanotificationsent","Casereturnedtoberkeleyfornewinf","Casereturnedfromberkeley","Caticomplete","Kitmothersent","Kitinfantsent","Kitchildsent","Kitadolescentsent","Kitmotherrefusedcode","Kitchildrefusedcode","Noresponsetoplea","Responsereceivedfromplea","Senttoinpersonfollowup","Kitmotherrecd","Kitchildrecvd","Thankyousent","Physrequestsent","Physresponsereceived"]
45
+ %w{Masterid Motherid Record_Owner Datereceived Lastatt Lastdisp Currphone Vacauthrecd Recollect Needpreincentive Active_Phone Recordsentformatching Recordreceivedfrommatching Sentpreincentive Releasedtocati Confirmedcaticontact Refused Deceasednotification Eligible Confirmationpacketsent Catiprotocolexhausted Newphonenumreleasedtocati Pleanotificationsent Casereturnedtoberkeleyfornewinf Casereturnedfromberkeley Caticomplete Kitmothersent Kitinfantsent Kitchildsent Kitadolescentsent Kitmotherrefusedcode Kitchildrefusedcode Noresponsetoplea Responsereceivedfromplea Senttoinpersonfollowup Kitmotherrecd Kitchildrecvd Thankyousent Physrequestsent Physresponsereceived}
46
+ end
47
+
48
+ def csv_file_header
49
+ csv_file_header_array.collect{|s|"\"#{s}\""}.join(',')
50
+ end
51
+
52
+ def csv_file_study_subject(options={})
53
+ subject = study_subject_hash.merge(options)
54
+ csv_file_header_array.collect{|s|"\"#{subject[s]}\""}.join(',')
55
+ end
56
+
57
+ def study_subject_hash
58
+ {
59
+ "Masterid" => "1234FAKE",
60
+ "Motherid" => "4567FAKE"
61
+
62
+ # "Record_Owner" => "ICF",
63
+ # "Datereceived" => "9/9/2011",
64
+ # "Lastatt" => "12/17/2011",
65
+ # "Lastdisp" => "113",
66
+ # "Currphone" => "2 of 2",
67
+ # "Vacauthrecd" => nil,
68
+ # "Recollect" => nil,
69
+ # "Needpreincentive" => "9/17/11 9:29 AM",
70
+ # "Active_Phone" => nil,
71
+ # "Recordsentformatching" => "9/16/2011",
72
+ # "Recordreceivedfrommatching" => "9/16/2011",
73
+ # "Sentpreincentive" => "9/17/2011",
74
+ # "Releasedtocati" => "9/17/2011",
75
+ # "Confirmedcaticontact" => "9/28/2011",
76
+ # "Refused" => "12/15/2011",
77
+ # "Deceasednotification" => nil,
78
+ # "Eligible" => nil,
79
+ # "Confirmationpacketsent" => nil,
80
+ # "Catiprotocolexhausted" => "12/17/2011",
81
+ # "Newphonenumreleasedtocati" => "11/14/2011",
82
+ # "Pleanotificationsent" => "11/14/2011",
83
+ # "Casereturnedtoberkeleyfornewinf" => "12/19/2011",
84
+ # "Casereturnedfromberkeley" => "12/22/2011",
85
+ # "Caticomplete" => nil,
86
+ # "Kitmothersent" => nil,
87
+ # "Kitinfantsent" => nil,
88
+ # "Kitchildsent" => nil,
89
+ # "Kitadolescentsent" => nil,
90
+ # "Kitmotherrefusedcode" => nil,
91
+ # "Kitchildrefusedcode" => nil,
92
+ # "Noresponsetoplea" => nil,
93
+ # "Responsereceivedfromplea" => nil,
94
+ # "Senttoinpersonfollowup" => nil,
95
+ # "Kitmotherrecd" => nil,
96
+ # "Kitchildrecvd" => nil,
97
+ # "Thankyousent" => nil,
98
+ # "Physrequestsent" => nil,
99
+ # "Physresponsereceived" => nil
100
+ }
101
+ end
102
+
103
+ def create_icf_master_tracker_update_test_file(options={})
104
+ File.open(csv_test_file_name,'w'){|f|
105
+ f.puts csv_file_header
106
+ f.puts csv_file_study_subject(options)
107
+ }
108
+ end
109
+
110
+ def turn_off_paperclip_logging
111
+ # Is there I way to silence the paperclip output? Yes...
112
+ Paperclip.options[:log] = false
113
+ # Is there I way to capture the paperclip output for comparison? Don't know.
114
+ end
115
+
116
+ # shouldn't be called test_... as makes it a test method!
117
+ def csv_test_file_name
118
+ "icf_master_tracker_update_test_file.csv"
119
+ end
120
+
121
+ end