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,286 @@
1
+ namespace :ccls do
2
+
3
+ desc "Dump data to xml files"
4
+ task :export_to_xml => :environment do
5
+ outdir = if Rails.env == 'production'
6
+ "/my/ruby/xml"
7
+ else
8
+ "."
9
+ end
10
+ %w( project enrollment study_subject
11
+ patient phone_number address addressing ).each do |model|
12
+ puts "Exporting #{model.pluralize} ..."
13
+ File.open("#{outdir}/#{model.pluralize}.xml",'w'){|f|
14
+ f.puts model.camelize.constantize.all.to_xml }
15
+ end
16
+ end
17
+
18
+ desc "Report data counts in database"
19
+ task :data_report => :environment do
20
+ puts
21
+ puts "Report data counts in database"
22
+ puts
23
+ printf "%-25s %5d\n", "StudySubject.count:", StudySubject.count
24
+
25
+ StudySubject.all(:select => "subject_type_id, COUNT(*) AS count",
26
+ :group => :subject_type_id ).each do |e|
27
+ printf "%-25s %5d\n", "subject_type = #{e.subject_type}:", e.count
28
+ end
29
+
30
+ %w{ case_control_type childidwho hispanicity_id father_hispanicity_id
31
+ mother_hispanicity_id sex do_not_contact }.each do |field|
32
+ StudySubject.all(:select => "#{field}, COUNT(*) AS count",
33
+ :group => field ).each do |e|
34
+ printf "%-25s %5d\n", "#{field} = #{e.send(field)}:", e.count
35
+ end
36
+ end
37
+
38
+ printf "%-25s %5d\n", "Patient.count:", Patient.count
39
+ %w{ was_under_15_at_dx was_previously_treated was_ca_resident_at_diagnosis
40
+ organization_id diagnosis_id
41
+ }.each do |field|
42
+ Patient.all(:select => "#{field}, COUNT(*) AS count",
43
+ :group => field ).each do |e|
44
+ printf "%-25s %5d\n", "#{field} = #{e.send(field)}:", e.count
45
+ end
46
+ end
47
+
48
+ printf "%-25s %5d\n", "Enrollment.count:", Enrollment.count
49
+ printf "%-25s %5d\n", "OperationalEvent.count:", OperationalEvent.count
50
+ %w{ operational_event_type_id }.each do |field|
51
+ OperationalEvent.all(:select => "#{field}, COUNT(*) AS count",
52
+ :group => field ).each do |e|
53
+ printf "%-25s %5d\n", "#{field} = #{e.send(field)}:", e.count
54
+ end
55
+ end
56
+
57
+ printf "%-25s %5d\n", "CCLS Enrollments.count:", Enrollment.count(
58
+ :conditions => { :project_id => Project['ccls'].id })
59
+ %w{ consented is_eligible refusal_reason_id document_version_id
60
+ ineligible_reason_id
61
+ }.each do |field|
62
+ Enrollment.all(:select => "#{field}, COUNT(*) AS count",
63
+ :conditions => { :project_id => Project['ccls'].id },
64
+ :group => field ).each do |e|
65
+ printf "%-25s %5d\n", "#{field} = #{e.send(field)}:", e.count
66
+ end
67
+ end
68
+
69
+ printf "%-25s %5d\n", "IcfMasterId.count:", IcfMasterId.count
70
+ printf "%-25s %5d\n", "Used IcfMasterId.count:", IcfMasterId.count(
71
+ :conditions => [ 'study_subject_id IS NOT NULL' ])
72
+ printf "%-25s %5d\n", "Unused IcfMasterId.count:", IcfMasterId.count(
73
+ :conditions => [ 'study_subject_id IS NULL' ])
74
+
75
+ printf "%-25s %5d\n", "Subjects with icf_master_id:", StudySubject.count(
76
+ :conditions => [ 'icf_master_id IS NOT NULL' ])
77
+ printf "%-25s %5d\n", "Subjects without icf_master_id:", StudySubject.count(
78
+ :conditions => [ 'icf_master_id IS NULL' ])
79
+
80
+ printf "%-25s %5d\n", "Subjects with childid:", StudySubject.count(
81
+ :conditions => [ 'childid IS NOT NULL' ])
82
+ printf "%-25s %5d\n", "Subjects without childid:", StudySubject.count(
83
+ :conditions => [ 'childid IS NULL' ])
84
+
85
+ printf "%-25s %5d\n", "Subjects with patid:", StudySubject.count(
86
+ :conditions => [ 'patid IS NOT NULL' ])
87
+ printf "%-25s %5d\n", "Subjects without patid:", StudySubject.count(
88
+ :conditions => [ 'patid IS NULL' ])
89
+
90
+ printf "%-25s %5d\n", "Subjects with studyid:", StudySubject.count(
91
+ :conditions => [ 'studyid IS NOT NULL' ])
92
+ printf "%-25s %5d\n", "Subjects without studyid:", StudySubject.count(
93
+ :conditions => [ 'studyid IS NULL' ])
94
+
95
+ printf "%-25s %5d\n", "Subjects with subjectid:", StudySubject.count(
96
+ :conditions => [ 'subjectid IS NOT NULL' ])
97
+ printf "%-25s %5d\n", "Subjects without subjectid:", StudySubject.count(
98
+ :conditions => [ 'subjectid IS NULL' ])
99
+
100
+ end
101
+
102
+ # task :sync_subject_type => :environment do
103
+ # abort("Don't do this in production! Not unless you know exactly what you're doing anyway."
104
+ # ) if Rails.env == 'production'
105
+ # Identifier.find(:all).each_with_index do |identifier,index|
106
+ # puts "Processing #{index}"
107
+ # study_subject = identifier.study_subject
108
+ # if study_subject.nil?
109
+ # puts "No study_subject on this identifier"
110
+ # next
111
+ # end
112
+ # puts "case_control_type #{identifier.case_control_type}"
113
+ # puts "subject_type #{study_subject.subject_type}"
114
+ # if study_subject.subject_type.to_s == 'Case' and identifier.case_control_type != 'C'
115
+ # puts "subject_type == 'Case' and case_control_type != 'C'"
116
+ # study_subject.patient.destroy unless study_subject.patient.nil?
117
+ # study_subject.reload.subject_type = SubjectType['Control']
118
+ # study_subject.save!
119
+ # puts "NEW subject_type #{study_subject.reload.subject_type}"
120
+ # end
121
+ # end
122
+ # end
123
+
124
+ desc "Load some fixtures to database for application"
125
+ task :update => :environment do
126
+ # gift_cards
127
+ fixtures = %w(
128
+ address_types
129
+ contexts
130
+ context_data_sources
131
+ data_sources
132
+ diagnoses
133
+ document_types
134
+ document_versions
135
+ follow_up_types
136
+ hospitals
137
+ ineligible_reasons
138
+ instrument_versions
139
+ instruments
140
+ interview_methods
141
+ interview_outcomes
142
+ instrument_types
143
+ languages
144
+ organizations
145
+ operational_event_types
146
+ people
147
+ phone_types
148
+ projects
149
+ races
150
+ refusal_reasons
151
+ roles
152
+ sample_outcomes
153
+ sample_temperatures
154
+ sample_types
155
+ sections
156
+ states
157
+ subject_relationships
158
+ subject_types
159
+ tracing_statuses
160
+ units
161
+ vital_statuses
162
+ )
163
+ ENV['FIXTURES'] = fixtures.join(',')
164
+ puts "Loading fixtures for #{ENV['FIXTURES']}"
165
+ Rake::Task["db:fixtures:load"].invoke
166
+ Rake::Task["db:fixtures:load"].reenable
167
+ end
168
+
169
+ task :full_update => :update do
170
+ #
171
+ # We don't use this yet, plus it hasn't changed, so why keep updating it?
172
+ # It takes about 30 minutes.
173
+ #
174
+ # # the zip_codes.csv fixtures is too big and takes too long to
175
+ # # load in testing, so I left a small one there and put
176
+ # # the full version from http://www.populardata.com/zipcode_database.html
177
+ fixtures = %w(
178
+ zip_codes
179
+ counties
180
+ )
181
+ # Do not import icf_master_ids this way in production as these are real
182
+ # icf_master_ids and some may be assigned to real subjects already.
183
+ # icf_master_ids
184
+ ENV['FIXTURES'] = fixtures.join(',')
185
+ ENV['FIXTURES_PATH'] = 'production/fixtures'
186
+ puts "Loading production fixtures for #{ENV['FIXTURES']}"
187
+ Rake::Task["db:fixtures:load"].invoke
188
+ Rake::Task["db:fixtures:load"].reenable
189
+ end
190
+
191
+ desc "Add some expected users."
192
+ task :add_users => :environment do
193
+ puts "Adding users"
194
+ %w( 859908 228181 214766 180918 66458 768475
195
+ 10883 86094 769067 ).each do |uid|
196
+ puts " - Adding user with uid:#{uid}:"
197
+ User.find_create_and_update_by_uid(uid)
198
+ end
199
+ end
200
+
201
+ desc "Add user by UID"
202
+ task :add_user => :environment do
203
+ puts
204
+ if ENV['uid'].blank?
205
+ puts "User's CalNet UID required."
206
+ puts "Usage: rake #{$*} uid=INTEGER"
207
+ puts
208
+ exit
209
+ end
210
+ if !User.exists?(:uid => ENV['uid'])
211
+ puts "No user found with uid=#{ENV['uid']}. Adding..."
212
+ User.find_create_and_update_by_uid(ENV['uid'])
213
+ else
214
+ puts "User with uid #{ENV['uid']} already exists."
215
+ end
216
+ puts
217
+ end
218
+
219
+ desc "Deputize user by UID"
220
+ task :deputize => :environment do
221
+ puts
222
+ if ENV['uid'].blank?
223
+ puts "User's CalNet UID required."
224
+ puts "Usage: rake #{$*} uid=INTEGER"
225
+ puts
226
+ exit
227
+ end
228
+ if !User.exists?(:uid => ENV['uid'])
229
+ puts "No user found with uid=#{ENV['uid']}."
230
+ puts
231
+ exit
232
+ end
233
+ user = User.find(:first, :conditions => { :uid => ENV['uid'] })
234
+ puts "Found user #{user.displayname}. Deputizing..."
235
+ user.deputize
236
+ puts "User deputized: #{user.is_administrator?}"
237
+ puts
238
+ end
239
+
240
+ end
241
+
242
+
243
+ __END__
244
+
245
+ # task :args_as_array do
246
+ # args = $*.dup.slice(1..-1)
247
+ # puts args.collect {|arg| "X:" << arg }.join("\n")
248
+ # exit
249
+ # end
250
+
251
+
252
+ Another way to pass arguments to rake task as demonstrated by one of the sunspot gem's tasks
253
+ ...
254
+ # This task depends on the standard Rails file naming \
255
+ # conventions, in that the file name matches the defined class name. \
256
+ # By default the indexing system works in batches of 50 records, you can \
257
+ # set your own value for this by using the batch_size argument. You can \
258
+ # also optionally define a list of models to separated by a forward slash '/'
259
+ #
260
+ # $ rake sunspot:reindex # reindex all models
261
+ # $ rake sunspot:reindex[1000] # reindex in batches of 1000
262
+ # $ rake sunspot:reindex[false] # reindex without batching
263
+ # $ rake sunspot:reindex[,Post] # reindex only the Post model
264
+ # $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
265
+ # # batchs of 1000
266
+ # $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
267
+ task :reindex, :batch_size, :models, :needs => :environment do |t, args|
268
+ reindex_options = {:batch_commit => false}
269
+ case args[:batch_size]
270
+ when 'false'
271
+ reindex_options[:batch_size] = nil
272
+ when /^\d+$/
273
+ reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
274
+ end
275
+ unless args[:models]
276
+ all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
277
+ all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
278
+ sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
279
+ else
280
+ sunspot_models = args[:models].split('+').map{|m| m.constantize}
281
+ end
282
+ sunspot_models.each do |model|
283
+ model.solr_reindex reindex_options
284
+ end
285
+ end
286
+
@@ -0,0 +1,6 @@
1
+ # From `script/generate calnet_authenticated` ...
2
+ # condition added to allow clean 'rake gems:install'
3
+ unless Gem.source_index.find_name('ccls-calnet_authenticated').empty?
4
+ gem 'ccls-calnet_authenticated'
5
+ require 'calnet_authenticated/test_tasks'
6
+ end
@@ -0,0 +1,7 @@
1
+ # From `script/generate ccls_common_lib` ...
2
+ # condition added to allow clean 'rake gems:install'
3
+ unless Gem.source_index.find_name('ccls-common_lib').empty?
4
+ gem 'ccls-common_lib'
5
+ require 'common_lib/tasks'
6
+ require 'common_lib/test_tasks'
7
+ end
@@ -0,0 +1,288 @@
1
+ namespace :db do
2
+
3
+ # desc "Import subject and address data from CSV files"
4
+ # task :import_csv_data => [
5
+ # :destroy_csv_data,
6
+ # :import_subject_data,
7
+ # :import_matchingid_and_familyid,
8
+ # :import_address_data,
9
+ # :random_enrollments_data
10
+ # ]
11
+
12
+ desc "Destroy subject and address data"
13
+ task :destroy_csv_data => :environment do
14
+ StudySubject.destroy_all
15
+ Enrollment.destroy_all
16
+ Addressing.destroy_all
17
+ Address.destroy_all
18
+ PhoneNumber.destroy_all
19
+ Interview.destroy_all
20
+ # Identifier.destroy_all
21
+ Patient.destroy_all
22
+ # Pii.destroy_all
23
+ # ResponseSet.destroy_all
24
+ # Response.destroy_all
25
+ Sample.destroy_all
26
+ SampleKit.destroy_all
27
+ # Package.destroy_all
28
+ HomexOutcome.destroy_all
29
+ InterviewOutcome.destroy_all
30
+ HomeExposureResponse.destroy_all
31
+ OperationalEvent.destroy_all
32
+ ProjectOutcome.destroy_all
33
+ SampleOutcome.destroy_all
34
+ # Track.destroy_all
35
+ Transfer.destroy_all
36
+ # SurveyInvitation.destroy_all
37
+ end
38
+
39
+ task :random_enrollments_data => :environment do
40
+ p = Project.find_or_create_by_code({
41
+ :code => "HomeExposures",
42
+ :description => "HomeExposures"
43
+ })
44
+ StudySubject.all.each do |s|
45
+ puts s.id
46
+ # 2440000 is sometime in 1968
47
+ # 2455000 is sometime in 2009
48
+
49
+ options = {
50
+ :study_subject => s,
51
+ :project => p,
52
+ :is_candidate => true,
53
+ :able_to_locate => true
54
+ }
55
+ options[:is_eligible] = [nil,1,2,999][rand(4)]
56
+ if options[:is_eligible] == 2
57
+ ir = IneligibleReason.random()
58
+ options[:ineligible_reason_id] = ir.id
59
+ if ir.is_other?
60
+ options[:ineligible_reason_specify] = "Random reason ineligible"
61
+ end
62
+ end
63
+
64
+ options[:is_chosen] = [nil,1,2,999][rand(4)]
65
+ if options[:is_chosen] == 2
66
+ options[:reason_not_chosen] = "Random reason not chosen"
67
+ end
68
+
69
+ options[:consented] = [nil,1,2,999][rand(4)]
70
+ if options[:consented] == 1
71
+ options[:consented_on] = Date.jd(2440000+rand(15000))
72
+ elsif options[:consented] == 2
73
+ options[:consented_on] = Date.jd(2440000+rand(15000))
74
+ rr = RefusalReason.random()
75
+ options[:refusal_reason_id] = rr.id
76
+ if rr.is_other?
77
+ options[:other_refusal_reason] = "Random refusal reason"
78
+ end
79
+ end
80
+
81
+ options[:terminated_participation] = [nil,1,2,999][rand(4)]
82
+ if options[:terminated_participation] == 1
83
+ options[:terminated_reason] = "Random terminated reason"
84
+ end
85
+
86
+ options[:is_complete] = [nil,1,2,999][rand(4)]
87
+ if options[:is_complete] == 1
88
+ options[:completed_on] = Date.jd(2440000+rand(15000))
89
+ end
90
+ Enrollment.create!(options)
91
+
92
+
93
+ options = {
94
+ :interview_outcome => InterviewOutcome.random(),
95
+ :sample_outcome => SampleOutcome.random()
96
+ }
97
+ if options[:interview_outcome]
98
+ options[:interview_outcome_on] = Date.jd(2440000+rand(15000))
99
+ end
100
+ if options[:sample_outcome]
101
+ options[:sample_outcome_on] = Date.jd(2440000+rand(15000))
102
+ end
103
+ s.build_homex_outcome(options)
104
+ s.save!
105
+ end
106
+ end
107
+
108
+ # desc "Import subject data from CSV file"
109
+ # task :import_subjectid => :environment do
110
+ # require 'fastercsv'
111
+ # # DO NOT COMMENT OUT THE HEADER LINE OR IT RAISES CRYPTIC ERROR
112
+ # (f=FasterCSV.open('misc/dummy_subject_pii_etc.csv', 'rb',{
113
+ # :headers => true })).each do |line|
114
+ ## Childid,patID,Type,OrderNo,subjectID,sex,DOB,RefDate,InterviewDate,First_Name,Middle_Name,Last_Name,Mother_First_Name,Mother_Middle_Name,Mother_Maiden_Name,Mother_Last_Name,Father_First_Name,Father_Middle_Name,Father_Last_Name,Primary_Phone,Alternate_phone1,Alternate_phone2,Alternate_phone3
115
+ # puts "Processing line #{f.lineno}"
116
+ # puts line
117
+ #
118
+ # # due to padding it with zeros, NEED this to be an Integer
119
+ # # doesn't work correctly in sqlite so just pad it before search
120
+ # identifier = Identifier.find_by_childid(
121
+ # sprintf("%06d",line['Childid'].to_i))
122
+ # raise ActiveRecord::RecordNotFound unless identifier
123
+ #
124
+ # identifier.update_attributes!(:subjectid => line['subjectID'])
125
+ #
126
+ # end
127
+ # end
128
+ #
129
+ # desc "Import matchingid and familyid data from CSV file"
130
+ # task :import_matchingid_and_familyid => :environment do
131
+ # require 'fastercsv'
132
+ # # DO NOT COMMENT OUT THE HEADER LINE OR IT RAISES CRYPTIC ERROR
133
+ # (f=FasterCSV.open('misc/subjectmatchingfamilyids_xref.csv', 'rb',{
134
+ # :headers => true })).each do |line|
135
+ ## subjectID,matchingID,familyid
136
+ # puts "Processing line #{f.lineno}"
137
+ # puts line
138
+ # if line['subjectID'] =~ /^\s*#/
139
+ # puts "skipping as subjectid not found"
140
+ # next
141
+ # end
142
+ #
143
+ # # due to padding it with zeros, NEED this to be an Integer
144
+ # # doesn't work correctly in sqlite so just pad it before search
145
+ # identifier = Identifier.find_by_subjectid(
146
+ # sprintf("%06d",line['subjectID'].to_i))
147
+ # raise ActiveRecord::RecordNotFound unless identifier
148
+ #
149
+ # identifier.update_attributes!(
150
+ # :matchingid => line['matchingID'],
151
+ # :familyid => line['familyid']
152
+ # )
153
+ #
154
+ # end
155
+ # end
156
+ #
157
+ # desc "Import address data from CSV file"
158
+ # task :import_address_data => :environment do
159
+ # require 'fastercsv'
160
+ # # DO NOT COMMENT OUT THE HEADER LINE OR IT RAISES CRYPTIC ERROR
161
+ # (f=FasterCSV.open('misc/dummy_addresses.csv', 'rb',{
162
+ # :headers => true })).each do |line|
163
+ ## subjectID,Address_Type_ID,Address_Line1,Address_City,Address_State,Address_Zip
164
+ # puts "Processing line #{f.lineno}"
165
+ # puts line
166
+ #
167
+ # # due to padding it with zeros, NEED this to be an Integer
168
+ # # doesn't work correctly in sqlite so just pad it before search
169
+ # study_subject = Identifier.find_by_subjectid(
170
+ # sprintf("%06d",line['subjectID'].to_i)).study_subject
171
+ # raise ActiveRecord::RecordNotFound unless study_subject
172
+ #
173
+ ## address_type = AddressType.find(line[1].to_s)
174
+ ## address_type = AddressType.find_by_code(
175
+ ## (line[1].to_s == '1')?'Home':'Mailing')
176
+ ## raise ActiveRecord::RecordNotFound unless address_type
177
+ #
178
+ ## study_subject.addressings << Addressing.create!(
179
+ ## :study_subject_id => study_subject.id,
180
+ # study_subject.addressings.create!(
181
+ # :current_address => 1, # Yes
182
+ # :is_valid => true,
183
+ # :is_verified => false,
184
+ # :address_attributes => {
185
+ # :address_type_id => line['Address_Type_ID'].to_i,
186
+ # :line_1 => line['Address_Line1']||"FAKE LINE 1",
187
+ # :city => line['Address_City']||"FAKE CITY",
188
+ # :state => line['Address_State']||"FAKE STATE",
189
+ # :zip => line['Address_Zip']||"12345-6789"
190
+ # }
191
+ # )
192
+ # end
193
+ # end
194
+ #
195
+ # desc "Import subject data from CSV file"
196
+ # task :import_subject_data => :environment do
197
+ # require 'fastercsv'
198
+ # # DO NOT COMMENT OUT THE HEADER LINE OR IT RAISES CRYPTIC ERROR
199
+ # (f=FasterCSV.open('misc/dummy_subject_pii_etc.csv', 'rb',{
200
+ # :headers => true })).each do |line|
201
+ ## Childid,patID,Type,OrderNo,subjectID,sex,DOB,RefDate,InterviewDate,First_Name,Middle_Name,Last_Name,Mother_First_Name,Mother_Middle_Name,Mother_Maiden_Name,Mother_Last_Name,Father_First_Name,Father_Middle_Name,Father_Last_Name,Primary_Phone,Alternate_phone1,Alternate_phone2,Alternate_phone3
202
+ # puts "Processing line #{f.lineno}"
203
+ # puts line
204
+ #
205
+ ## subject_type = SubjectType['Case']
206
+ # subject_type = SubjectType.random()
207
+ #
208
+ # # TODO (not included in csv)
209
+ ## race = Race[1]
210
+ # race = Race.random()
211
+ #
212
+ # dob = (line['DOB'].blank?)?'':Time.parse(line['DOB'])
213
+ # refdate = (line['RefDate'].blank?)?'':Time.parse(line['RefDate'])
214
+ # interview_date = (line['InterviewDate'].blank?)?'':Time.parse(line['InterviewDate'])
215
+ # study_subject = StudySubject.create!({
216
+ ## :patient_attributes => { }, # TODO (patid)
217
+ # :pii_attributes => {
218
+ # :first_name => line['First_Name'],
219
+ # :middle_name => line['Middle_Name'],
220
+ # :last_name => line['Last_Name'],
221
+ # :father_first_name => line['Father_First_Name'],
222
+ # :father_middle_name => line['Father_Middle_Name'],
223
+ # :father_last_name => line['Father_Last_Name'],
224
+ # :mother_first_name => line['Mother_First_Name'],
225
+ # :mother_middle_name => line['Mother_Middle_Name'],
226
+ # :mother_maiden_name => line['Mother_Maiden_Name'],
227
+ # :mother_last_name => line['Mother_Last_Name'],
228
+ # :dob => dob
229
+ # },
230
+ # :identifier_attributes => {
231
+ # :state_id_no => sprintf('%09d',line['Childid']), # TODO
232
+ # :subjectid => line['subjectID'],
233
+ # :ssn => sprintf('%09d',line['Childid']), # TODO
234
+ # :patid => line['patID'],
235
+ # :case_control_type => line['Type'],
236
+ # :orderno => line['OrderNo'],
237
+ # :childid => line['Childid']
238
+ # },
239
+ # :subject_type => subject_type,
240
+ # :sex => line['sex'],
241
+ # :reference_date => refdate
242
+ # })
243
+ # study_subject.races = [race]
244
+ #
245
+ ## Identifier.create!({
246
+ ## :study_subject_id => study_subject.id,
247
+ ## :state_id_no => sprintf('%09d',line['Childid']), # TODO
248
+ ## :subjectid => line['subjectID'],
249
+ ## :ssn => sprintf('%09d',line['Childid']), # TODO
250
+ ## :patid => line['patID'],
251
+ ## :case_control_type => line['Type'],
252
+ ## :orderno => line['OrderNo'],
253
+ ## :childid => line['Childid']
254
+ ## })
255
+ #
256
+ # (19..22).each do |i|
257
+ ## PhoneNumber.create!({
258
+ # study_subject.phone_numbers.create!({
259
+ ## :study_subject_id => study_subject.id,
260
+ # :phone_type_id => 1,
261
+ # :phone_number => line[i]
262
+ # }) unless line[i].blank?
263
+ # end
264
+ #
265
+ # options = {
266
+ ## :identifier_id => study_subject.identifier.id,
267
+ # :interview_method => InterviewMethod.random(),
268
+ # :interviewer => Person.random(),
269
+ # :language => Language.random(),
270
+ # :instrument_version => InstrumentVersion.random(),
271
+ # :began_on => interview_date,
272
+ # :ended_on => interview_date
273
+ # }
274
+ # options[:subject_relationship] = SubjectRelationship.random()
275
+ # if options[:subject_relationship].is_other?
276
+ # options[:subject_relationship_other] = 'super unknown god buddy'
277
+ # end
278
+ #
279
+ ## Interview.create!(options)
280
+ # study_subject.interviews.create!(options)
281
+ #
282
+ ## use Time.parse to parse all dates (better than Date.parse)
283
+ #
284
+ ## need ssn, state_id_no in data (making it up now)
285
+ #
286
+ # end
287
+ # end
288
+ end