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.
- data/README.rdoc +182 -0
- data/app/models/abstract.rb +181 -0
- data/app/models/abstract_search.rb +50 -0
- data/app/models/abstract_validations.rb +324 -0
- data/app/models/address.rb +70 -0
- data/app/models/address_type.rb +15 -0
- data/app/models/addressing.rb +147 -0
- data/app/models/aliquot.rb +44 -0
- data/app/models/aliquot_sample_format.rb +13 -0
- data/app/models/analysis.rb +14 -0
- data/app/models/bc_request.rb +20 -0
- data/app/models/candidate_control.rb +101 -0
- data/app/models/context.rb +23 -0
- data/app/models/context_data_source.rb +4 -0
- data/app/models/county.rb +16 -0
- data/app/models/data_source.rb +24 -0
- data/app/models/diagnosis.rb +23 -0
- data/app/models/document_type.rb +16 -0
- data/app/models/document_version.rb +27 -0
- data/app/models/enrollment.rb +78 -0
- data/app/models/enrollment_validations.rb +167 -0
- data/app/models/follow_up.rb +16 -0
- data/app/models/follow_up_type.rb +18 -0
- data/app/models/gift_card.rb +22 -0
- data/app/models/gift_card_search.rb +137 -0
- data/app/models/home_exposure_response.rb +24 -0
- data/app/models/homex_outcome.rb +75 -0
- data/app/models/hospital.rb +22 -0
- data/app/models/icf_master_id.rb +30 -0
- data/app/models/icf_master_tracker.rb +217 -0
- data/app/models/icf_master_tracker_change.rb +9 -0
- data/app/models/icf_master_tracker_update.rb +50 -0
- data/app/models/ineligible_reason.rb +26 -0
- data/app/models/instrument.rb +26 -0
- data/app/models/instrument_type.rb +17 -0
- data/app/models/instrument_version.rb +28 -0
- data/app/models/interview.rb +122 -0
- data/app/models/interview_method.rb +17 -0
- data/app/models/interview_outcome.rb +16 -0
- data/app/models/language.rb +28 -0
- data/app/models/live_birth_data_update.rb +142 -0
- data/app/models/operational_event.rb +99 -0
- data/app/models/operational_event_type.rb +31 -0
- data/app/models/organization.rb +28 -0
- data/app/models/patient.rb +63 -0
- data/app/models/patient_validations.rb +118 -0
- data/app/models/person.rb +28 -0
- data/app/models/phone_number.rb +105 -0
- data/app/models/phone_type.rb +15 -0
- data/app/models/project.rb +39 -0
- data/app/models/project_outcome.rb +19 -0
- data/app/models/race.rb +31 -0
- data/app/models/refusal_reason.rb +23 -0
- data/app/models/sample.rb +168 -0
- data/app/models/sample_kit.rb +14 -0
- data/app/models/sample_outcome.rb +16 -0
- data/app/models/sample_temperature.rb +14 -0
- data/app/models/sample_type.rb +37 -0
- data/app/models/search.rb +195 -0
- data/app/models/section.rb +18 -0
- data/app/models/state.rb +25 -0
- data/app/models/study_subject.rb +237 -0
- data/app/models/study_subject_abstracts.rb +47 -0
- data/app/models/study_subject_addresses.rb +34 -0
- data/app/models/study_subject_associations.rb +38 -0
- data/app/models/study_subject_duplicates.rb +111 -0
- data/app/models/study_subject_enrollments.rb +17 -0
- data/app/models/study_subject_homex_outcome.rb +22 -0
- data/app/models/study_subject_identifier.rb +153 -0
- data/app/models/study_subject_interviews.rb +25 -0
- data/app/models/study_subject_languages.rb +21 -0
- data/app/models/study_subject_operational_events.rb +66 -0
- data/app/models/study_subject_patient.rb +177 -0
- data/app/models/study_subject_pii.rb +74 -0
- data/app/models/study_subject_races.rb +25 -0
- data/app/models/study_subject_search.rb +260 -0
- data/app/models/study_subject_validations.rb +116 -0
- data/app/models/subject_language.rb +11 -0
- data/app/models/subject_race.rb +11 -0
- data/app/models/subject_relationship.rb +21 -0
- data/app/models/subject_type.rb +22 -0
- data/app/models/tracing_status.rb +20 -0
- data/app/models/transfer.rb +40 -0
- data/app/models/unit.rb +14 -0
- data/app/models/vital_status.rb +19 -0
- data/app/models/zip_code.rb +36 -0
- data/config/abstract_fields.yml +1038 -0
- data/config/abstract_sections.yml +77 -0
- data/config/home_exposure_response_fields.yml +583 -0
- data/config/icf_master_tracker_update.yml +56 -0
- data/config/live_birth_data_update.yml +56 -0
- data/config/shared_use_db.yml +4 -0
- data/generators/ccls_engine/USAGE +2 -0
- data/generators/ccls_engine/ccls_engine_generator.rb +123 -0
- data/generators/ccls_engine/templates/autotest_ccls_engine.rb +3 -0
- data/generators/ccls_engine/templates/ccls_engine.rake +12 -0
- data/generators/ccls_engine/templates/fixtures/address_types.yml +30 -0
- data/generators/ccls_engine/templates/fixtures/context_data_sources.yml +54 -0
- data/generators/ccls_engine/templates/fixtures/contexts.yml +19 -0
- data/generators/ccls_engine/templates/fixtures/data_sources.yml +40 -0
- data/generators/ccls_engine/templates/fixtures/diagnoses.yml +40 -0
- data/generators/ccls_engine/templates/fixtures/document_types.yml +65 -0
- data/generators/ccls_engine/templates/fixtures/document_versions.csv +155 -0
- data/generators/ccls_engine/templates/fixtures/follow_up_types.yml +16 -0
- data/generators/ccls_engine/templates/fixtures/hospitals.yml +114 -0
- data/generators/ccls_engine/templates/fixtures/ineligible_reasons.yml +35 -0
- data/generators/ccls_engine/templates/fixtures/instrument_types.yml +26 -0
- data/generators/ccls_engine/templates/fixtures/instrument_versions.yml +22 -0
- data/generators/ccls_engine/templates/fixtures/instruments.yml +22 -0
- data/generators/ccls_engine/templates/fixtures/interview_methods.yml +30 -0
- data/generators/ccls_engine/templates/fixtures/interview_outcomes.yml +31 -0
- data/generators/ccls_engine/templates/fixtures/languages.yml +34 -0
- data/generators/ccls_engine/templates/fixtures/operational_event_types.yml +141 -0
- data/generators/ccls_engine/templates/fixtures/organizations.yml +198 -0
- data/generators/ccls_engine/templates/fixtures/people.yml +130 -0
- data/generators/ccls_engine/templates/fixtures/phone_types.yml +30 -0
- data/generators/ccls_engine/templates/fixtures/project_outcomes.yml +25 -0
- data/generators/ccls_engine/templates/fixtures/projects.yml +59 -0
- data/generators/ccls_engine/templates/fixtures/races.yml +52 -0
- data/generators/ccls_engine/templates/fixtures/refusal_reasons.yml +55 -0
- data/generators/ccls_engine/templates/fixtures/sample_outcomes.yml +36 -0
- data/generators/ccls_engine/templates/fixtures/sample_temperatures.yml +16 -0
- data/generators/ccls_engine/templates/fixtures/sample_types.yml +147 -0
- data/generators/ccls_engine/templates/fixtures/sections.yml +31 -0
- data/generators/ccls_engine/templates/fixtures/states.yml +363 -0
- data/generators/ccls_engine/templates/fixtures/subject_relationships.yml +46 -0
- data/generators/ccls_engine/templates/fixtures/subject_types.yml +30 -0
- data/generators/ccls_engine/templates/fixtures/tracing_statuses.yml +30 -0
- data/generators/ccls_engine/templates/fixtures/units.yml +13 -0
- data/generators/ccls_engine/templates/fixtures/vital_statuses.yml +28 -0
- data/generators/ccls_engine/templates/functional/roles_controller_test.rb +142 -0
- data/generators/ccls_engine/templates/functional/sessions_controller_test.rb +19 -0
- data/generators/ccls_engine/templates/functional/users_controller_test.rb +94 -0
- data/generators/ccls_engine/templates/images/sort_down.png +0 -0
- data/generators/ccls_engine/templates/images/sort_up.png +0 -0
- data/generators/ccls_engine/templates/initializer.rb +28 -0
- data/generators/ccls_engine/templates/javascripts/ccls_engine.js +24 -0
- data/generators/ccls_engine/templates/javascripts/jquery-ui.js +763 -0
- data/generators/ccls_engine/templates/javascripts/jquery.js +154 -0
- data/generators/ccls_engine/templates/javascripts/jrails.js +1 -0
- data/generators/ccls_engine/templates/migrations/create_user_invitations.rb +18 -0
- data/generators/ccls_engine/templates/migrations/create_users.rb +33 -0
- data/generators/ccls_engine/templates/migrations/drop_user_invitations.rb +18 -0
- data/generators/ccls_engine/templates/stylesheets/ccls_engine.css +180 -0
- data/generators/ccls_engine/templates/stylesheets/user.css +35 -0
- data/generators/ccls_engine/templates/stylesheets/users.css +23 -0
- data/generators/ccls_engine/templates/unit/core_extension_test.rb +18 -0
- data/generators/ccls_engine/templates/unit/role_test.rb +30 -0
- data/generators/ccls_engine/templates/unit/user_test.rb +321 -0
- data/lib/ccls-ccls_engine.rb +1 -0
- data/lib/ccls_engine.rb +135 -0
- data/lib/ccls_engine/action_view_extension.rb +3 -0
- data/lib/ccls_engine/action_view_extension/base.rb +53 -0
- data/lib/ccls_engine/action_view_extension/form_builder.rb +39 -0
- data/lib/ccls_engine/active_record_extension.rb +2 -0
- data/lib/ccls_engine/active_record_extension/base.rb +70 -0
- data/lib/ccls_engine/active_record_shared.rb +8 -0
- data/lib/ccls_engine/assertions.rb +69 -0
- data/lib/ccls_engine/autotest.rb +54 -0
- data/lib/ccls_engine/ccls_user.rb +117 -0
- data/lib/ccls_engine/core_extension.rb +14 -0
- data/lib/ccls_engine/date_and_time_formats.rb +30 -0
- data/lib/ccls_engine/factories.rb +880 -0
- data/lib/ccls_engine/factory_test_helper.rb +276 -0
- data/lib/ccls_engine/helper.rb +112 -0
- data/lib/ccls_engine/icf_master_tracker_update_test_helper.rb +121 -0
- data/lib/ccls_engine/live_birth_data_update_test_helper.rb +110 -0
- data/lib/ccls_engine/package_test_helper.rb +49 -0
- data/lib/ccls_engine/shared_database.rb +20 -0
- data/lib/ccls_engine/tasks.rb +1 -0
- data/lib/ccls_engine/test_tasks.rb +52 -0
- data/lib/ccls_engine/translation_table.rb +86 -0
- data/lib/shared_migration.rb +5 -0
- data/lib/surveyor/survey_extensions.rb +125 -0
- data/lib/tasks/application.rake +286 -0
- data/lib/tasks/calnet_authenticated.rake +6 -0
- data/lib/tasks/common_lib.rake +7 -0
- data/lib/tasks/database.rake +288 -0
- data/lib/tasks/documentation.rake +71 -0
- data/lib/tasks/homex_import.rake +723 -0
- data/lib/tasks/odms_import.rake +1116 -0
- data/lib/tasks/simply_authorized.rake +6 -0
- data/lib/tasks/ucb_ccls_engine_tasks.rake +4 -0
- data/lib/tasks/use_db.rake +4 -0
- data/rails/init.rb +4 -0
- data/test/unit/ccls/abstract_search_test.rb +150 -0
- data/test/unit/ccls/abstract_test.rb +674 -0
- data/test/unit/ccls/address_test.rb +155 -0
- data/test/unit/ccls/address_type_test.rb +25 -0
- data/test/unit/ccls/addressing_test.rb +466 -0
- data/test/unit/ccls/aliquot_sample_format_test.rb +20 -0
- data/test/unit/ccls/aliquot_test.rb +156 -0
- data/test/unit/ccls/analysis_test.rb +31 -0
- data/test/unit/ccls/bc_request_test.rb +43 -0
- data/test/unit/ccls/candidate_control_test.rb +712 -0
- data/test/unit/ccls/context_data_source_test.rb +26 -0
- data/test/unit/ccls/context_test.rb +40 -0
- data/test/unit/ccls/core_extension_test.rb +17 -0
- data/test/unit/ccls/county_test.rb +34 -0
- data/test/unit/ccls/data_source_test.rb +41 -0
- data/test/unit/ccls/diagnosis_test.rb +51 -0
- data/test/unit/ccls/document_type_test.rb +35 -0
- data/test/unit/ccls/document_version_test.rb +68 -0
- data/test/unit/ccls/enrollment_test.rb +575 -0
- data/test/unit/ccls/follow_up_test.rb +23 -0
- data/test/unit/ccls/follow_up_type_test.rb +34 -0
- data/test/unit/ccls/gift_card_search_test.rb +153 -0
- data/test/unit/ccls/gift_card_test.rb +40 -0
- data/test/unit/ccls/home_exposure_response_test.rb +83 -0
- data/test/unit/ccls/homex_outcome_test.rb +199 -0
- data/test/unit/ccls/hospital_test.rb +102 -0
- data/test/unit/ccls/icf_master_id_test.rb +30 -0
- data/test/unit/ccls/icf_master_tracker_change_test.rb +14 -0
- data/test/unit/ccls/icf_master_tracker_test.rb +132 -0
- data/test/unit/ccls/icf_master_tracker_update_test.rb +176 -0
- data/test/unit/ccls/ineligible_reason_test.rb +48 -0
- data/test/unit/ccls/instrument_test.rb +62 -0
- data/test/unit/ccls/instrument_type_test.rb +39 -0
- data/test/unit/ccls/instrument_version_test.rb +71 -0
- data/test/unit/ccls/interview_method_test.rb +44 -0
- data/test/unit/ccls/interview_outcome_test.rb +34 -0
- data/test/unit/ccls/interview_test.rb +298 -0
- data/test/unit/ccls/language_test.rb +47 -0
- data/test/unit/ccls/live_birth_data_update_test.rb +358 -0
- data/test/unit/ccls/operational_event_test.rb +187 -0
- data/test/unit/ccls/operational_event_type_test.rb +51 -0
- data/test/unit/ccls/organization_test.rb +64 -0
- data/test/unit/ccls/patient_test.rb +538 -0
- data/test/unit/ccls/person_test.rb +55 -0
- data/test/unit/ccls/phone_number_test.rb +244 -0
- data/test/unit/ccls/phone_type_test.rb +32 -0
- data/test/unit/ccls/project_outcome_test.rb +34 -0
- data/test/unit/ccls/project_test.rb +60 -0
- data/test/unit/ccls/race_test.rb +37 -0
- data/test/unit/ccls/refusal_reason_test.rb +52 -0
- data/test/unit/ccls/role_test.rb +26 -0
- data/test/unit/ccls/sample_kit_test.rb +35 -0
- data/test/unit/ccls/sample_outcome_test.rb +34 -0
- data/test/unit/ccls/sample_temperature_test.rb +25 -0
- data/test/unit/ccls/sample_test.rb +363 -0
- data/test/unit/ccls/sample_type_test.rb +58 -0
- data/test/unit/ccls/section_test.rb +34 -0
- data/test/unit/ccls/state_test.rb +31 -0
- data/test/unit/ccls/study_subject_abstracts_test.rb +115 -0
- data/test/unit/ccls/study_subject_addresses_test.rb +93 -0
- data/test/unit/ccls/study_subject_duplicates_test.rb +407 -0
- data/test/unit/ccls/study_subject_enrollments_test.rb +65 -0
- data/test/unit/ccls/study_subject_homex_outcome_test.rb +64 -0
- data/test/unit/ccls/study_subject_identifier_test.rb +439 -0
- data/test/unit/ccls/study_subject_interviews_test.rb +26 -0
- data/test/unit/ccls/study_subject_languages_test.rb +142 -0
- data/test/unit/ccls/study_subject_operational_events_test.rb +53 -0
- data/test/unit/ccls/study_subject_patient_test.rb +249 -0
- data/test/unit/ccls/study_subject_pii_test.rb +278 -0
- data/test/unit/ccls/study_subject_races_test.rb +203 -0
- data/test/unit/ccls/study_subject_search_test.rb +704 -0
- data/test/unit/ccls/study_subject_test.rb +770 -0
- data/test/unit/ccls/subject_language_test.rb +43 -0
- data/test/unit/ccls/subject_race_test.rb +35 -0
- data/test/unit/ccls/subject_relationship_test.rb +43 -0
- data/test/unit/ccls/subject_type_test.rb +40 -0
- data/test/unit/ccls/tracing_status_test.rb +32 -0
- data/test/unit/ccls/transfer_test.rb +81 -0
- data/test/unit/ccls/translation_table_test.rb +40 -0
- data/test/unit/ccls/unit_test.rb +21 -0
- data/test/unit/ccls/user_test.rb +156 -0
- data/test/unit/ccls/vital_status_test.rb +36 -0
- data/test/unit/ccls/zip_code_test.rb +55 -0
- metadata +633 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::ContextDataSourceTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_create_default_object
|
|
6
|
+
assert_should_initially_belong_to( :context, :data_source )
|
|
7
|
+
|
|
8
|
+
test "explicit Factory context_data_source test" do
|
|
9
|
+
assert_difference('DataSource.count',1) {
|
|
10
|
+
assert_difference('Context.count',1) {
|
|
11
|
+
assert_difference('ContextDataSource.count',1) {
|
|
12
|
+
context_data_source = Factory(:context_data_source)
|
|
13
|
+
assert_not_nil context_data_source.context
|
|
14
|
+
assert_not_nil context_data_source.data_source
|
|
15
|
+
} } }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# def create_context_data_source(options={})
|
|
21
|
+
# context_data_source = Factory.build(:context_data_source,options)
|
|
22
|
+
# context_data_source.save
|
|
23
|
+
# context_data_source
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::ContextTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_behave_like_a_hash
|
|
6
|
+
|
|
7
|
+
assert_should_create_default_object
|
|
8
|
+
assert_should_not_require_attributes( :position, :notes )
|
|
9
|
+
assert_should_require_attribute_length( :notes, :maximum => 65000 )
|
|
10
|
+
assert_should_act_as_list
|
|
11
|
+
assert_should_have_many(:units)
|
|
12
|
+
|
|
13
|
+
test "explicit Factory context test" do
|
|
14
|
+
assert_difference('Context.count',1) {
|
|
15
|
+
context = Factory(:context)
|
|
16
|
+
assert_match /Key\d*/, context.key
|
|
17
|
+
assert_match /Desc\d*/, context.description
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "should return description as to_s" do
|
|
22
|
+
context = create_context
|
|
23
|
+
assert_equal context.description,
|
|
24
|
+
"#{context}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "should have many context_data_sources" do
|
|
28
|
+
context = Context[:addresses]
|
|
29
|
+
assert !context.context_data_sources.empty?
|
|
30
|
+
assert_difference('ContextDataSource.count',1) {
|
|
31
|
+
context.data_sources << Factory(:data_source)
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test "should have many data_sources through context_data_sources" do
|
|
36
|
+
context = Context[:addresses]
|
|
37
|
+
assert !context.data_sources.empty?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::CoreExtensionTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "this class exists" do
|
|
6
|
+
assert class_exists?('Ccls::CoreExtensionTest')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test "non class exists but is not a class" do
|
|
10
|
+
assert !class_exists?('Ccls::UcbCclsEngineHelper')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "bogus class does not exist" do
|
|
14
|
+
assert !class_exists?('SomeBogusClass')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::CountyTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_create_default_object
|
|
6
|
+
assert_should_have_many(:zip_codes)
|
|
7
|
+
assert_should_require( :name, :state_abbrev )
|
|
8
|
+
assert_should_not_require( :fips_code )
|
|
9
|
+
assert_should_require_length( :name, :maximum => 250 )
|
|
10
|
+
assert_should_require_length( :state_abbrev, :maximum => 2 )
|
|
11
|
+
assert_should_require_length( :fips_code, :maximum => 5 )
|
|
12
|
+
|
|
13
|
+
test "explicit Factory county test" do
|
|
14
|
+
assert_difference('County.count',1) {
|
|
15
|
+
county = Factory(:county)
|
|
16
|
+
assert_match /Name \d*/, county.name
|
|
17
|
+
assert_equal 'XX', county.state_abbrev
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "should return name and state as to_s" do
|
|
22
|
+
county = create_county
|
|
23
|
+
assert_equal "#{county.name}, #{county.state_abbrev}", "#{county}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#protected
|
|
27
|
+
#
|
|
28
|
+
# def create_county(options={})
|
|
29
|
+
# county = Factory.build(:county,options)
|
|
30
|
+
# county.save
|
|
31
|
+
# county
|
|
32
|
+
# end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::DataSourceTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_behave_like_a_hash
|
|
6
|
+
|
|
7
|
+
assert_should_create_default_object
|
|
8
|
+
assert_should_act_as_list
|
|
9
|
+
assert_should_not_require_attributes(
|
|
10
|
+
:position,
|
|
11
|
+
:organization_id,
|
|
12
|
+
:other_organization,
|
|
13
|
+
:person_id,
|
|
14
|
+
:other_person,
|
|
15
|
+
:data_origin )
|
|
16
|
+
assert_should_require_attribute_length(
|
|
17
|
+
:other_organization,
|
|
18
|
+
:other_person,
|
|
19
|
+
:data_origin,
|
|
20
|
+
:maximum => 250 )
|
|
21
|
+
|
|
22
|
+
test "explicit Factory data_source test" do
|
|
23
|
+
assert_difference('DataSource.count',1) {
|
|
24
|
+
data_source = Factory(:data_source)
|
|
25
|
+
assert_match /Key\d*/, data_source.key
|
|
26
|
+
assert_match /Desc\d*/, data_source.description
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test "should return description as to_s" do
|
|
31
|
+
data_source = create_data_source
|
|
32
|
+
assert_equal data_source.description,
|
|
33
|
+
"#{data_source}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "should return true for is_other if is other" do
|
|
37
|
+
data_source = DataSource['Other']
|
|
38
|
+
assert data_source.is_other?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::DiagnosisTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_behave_like_a_hash
|
|
6
|
+
|
|
7
|
+
assert_should_create_default_object
|
|
8
|
+
assert_should_require_attributes( :code )
|
|
9
|
+
assert_should_require_unique_attributes( :code )
|
|
10
|
+
assert_should_not_require_attributes(:position)
|
|
11
|
+
assert_should_act_as_list
|
|
12
|
+
# NOTE code is an integer for diagnosis (so key is used)
|
|
13
|
+
|
|
14
|
+
test "explicit Factory diagnosis test" do
|
|
15
|
+
assert_difference('Diagnosis.count',1) {
|
|
16
|
+
diagnosis = Factory(:diagnosis)
|
|
17
|
+
assert_match /key\d*/, diagnosis.key
|
|
18
|
+
assert_match /\d*/, diagnosis.code.to_s
|
|
19
|
+
assert_match /Desc\d*/, diagnosis.description
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "should return description as to_s" do
|
|
24
|
+
diagnosis = create_diagnosis
|
|
25
|
+
assert_equal diagnosis.description, "#{diagnosis}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "Diagnosis['other'] should return true for is_other?" do
|
|
29
|
+
diagnosis = Diagnosis['other']
|
|
30
|
+
assert diagnosis.is_other?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test "Diagnosis['ALL'] should return false for is_other?" do
|
|
34
|
+
diagnosis = Diagnosis['ALL']
|
|
35
|
+
assert !diagnosis.is_other?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test "Diagnosis['AML'] should return false for is_other?" do
|
|
39
|
+
diagnosis = Diagnosis['AML']
|
|
40
|
+
assert !diagnosis.is_other?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#protected
|
|
44
|
+
#
|
|
45
|
+
# def create_diagnosis(options={})
|
|
46
|
+
# diagnosis = Factory.build(:diagnosis,options)
|
|
47
|
+
# diagnosis.save
|
|
48
|
+
# diagnosis
|
|
49
|
+
# end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::DocumentTypeTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_create_default_object
|
|
6
|
+
assert_should_act_as_list
|
|
7
|
+
assert_should_have_many(:document_versions)
|
|
8
|
+
assert_should_require_attributes( :title )
|
|
9
|
+
assert_should_not_require_attributes( :position, :description )
|
|
10
|
+
assert_should_require_attribute_length(
|
|
11
|
+
:title,
|
|
12
|
+
:description,
|
|
13
|
+
:maximum => 250 )
|
|
14
|
+
|
|
15
|
+
test "explicit Factory document_type test" do
|
|
16
|
+
assert_difference('DocumentType.count',1) {
|
|
17
|
+
document_type = Factory(:document_type)
|
|
18
|
+
assert_match /Title\d*/, document_type.title
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "should return title as to_s" do
|
|
23
|
+
document_type = create_document_type
|
|
24
|
+
assert_equal document_type.title, "#{document_type}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#protected
|
|
28
|
+
#
|
|
29
|
+
# def create_document_type(options={})
|
|
30
|
+
# document_type = Factory.build(:document_type,options)
|
|
31
|
+
# document_type.save
|
|
32
|
+
# document_type
|
|
33
|
+
# end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::DocumentVersionTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
assert_should_create_default_object
|
|
6
|
+
assert_should_act_as_list
|
|
7
|
+
assert_should_initially_belong_to(:document_type)
|
|
8
|
+
assert_should_belong_to( :language )
|
|
9
|
+
assert_should_not_require_attributes( :position, :title, :description, :indicator,
|
|
10
|
+
:language_id, :began_use_on, :ended_use_on )
|
|
11
|
+
assert_should_require_attribute_length( :title, :description, :indicator,
|
|
12
|
+
:maximum => 250 )
|
|
13
|
+
assert_requires_complete_date( :began_use_on, :ended_use_on )
|
|
14
|
+
|
|
15
|
+
test "explicit Factory document_version test" do
|
|
16
|
+
assert_difference('DocumentType.count',1) {
|
|
17
|
+
assert_difference('DocumentVersion.count',1) {
|
|
18
|
+
document_version = Factory(:document_version)
|
|
19
|
+
assert_match /Title\d*/, document_version.title
|
|
20
|
+
assert_not_nil document_version.document_type
|
|
21
|
+
} }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test "should require document_type" do
|
|
25
|
+
assert_difference( "DocumentVersion.count", 0 ) do
|
|
26
|
+
document_version = create_document_version( :document_type => nil)
|
|
27
|
+
assert !document_version.errors.on(:document_type)
|
|
28
|
+
assert document_version.errors.on_attr_and_type?(:document_type_id, :blank)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "should require valid document_type" do
|
|
33
|
+
assert_difference( "DocumentVersion.count", 0 ) do
|
|
34
|
+
document_version = create_document_version( :document_type_id => 0)
|
|
35
|
+
assert !document_version.errors.on(:document_type_id)
|
|
36
|
+
assert document_version.errors.on_attr_and_type?(:document_type,:blank)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
test "should only return document type id == 1 for type1" do
|
|
41
|
+
objects = DocumentVersion.type1
|
|
42
|
+
assert_not_nil objects
|
|
43
|
+
objects.each do |o|
|
|
44
|
+
assert_equal 1, o.document_type_id
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test "should return title as to_s" do
|
|
49
|
+
document_version = create_document_version
|
|
50
|
+
assert_equal document_version.title, "#{document_version}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test "should have many consented enrollments" do
|
|
54
|
+
document_version = create_document_version
|
|
55
|
+
assert_equal 0, document_version.enrollments.length
|
|
56
|
+
document_version.enrollments << Factory(:consented_enrollment)
|
|
57
|
+
assert_equal 1, document_version.reload.enrollments.length
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#protected
|
|
61
|
+
#
|
|
62
|
+
# def create_document_version(options={})
|
|
63
|
+
# document_version = Factory.build(:document_version,options)
|
|
64
|
+
# document_version.save
|
|
65
|
+
# document_version
|
|
66
|
+
# end
|
|
67
|
+
|
|
68
|
+
end
|
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::EnrollmentTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
[ :use_smp_future_rsrch,
|
|
6
|
+
:use_smp_future_cancer_rsrch, :use_smp_future_other_rsrch,
|
|
7
|
+
:share_smp_with_others, :contact_for_related_study,
|
|
8
|
+
:provide_saliva_smp, :receive_study_findings ].each do |field|
|
|
9
|
+
|
|
10
|
+
# Making assumption that 12345 will NEVER be a valid value.
|
|
11
|
+
test "should NOT allow 12345 for #{field}" do
|
|
12
|
+
enrollment = Enrollment.new(field => 12345)
|
|
13
|
+
enrollment.valid?
|
|
14
|
+
assert enrollment.errors.on_attr_and_type?(field,:inclusion)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "should allow nil for #{field}" do
|
|
18
|
+
enrollment = Enrollment.new(field => nil)
|
|
19
|
+
assert_nil enrollment.send(field)
|
|
20
|
+
enrollment.valid?
|
|
21
|
+
assert !enrollment.errors.on(field)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test "should allow all valid ADNA values for #{field}" do
|
|
25
|
+
enrollment = Enrollment.new
|
|
26
|
+
ADNA.valid_values.each do |value|
|
|
27
|
+
enrollment.send("#{field}=", value)
|
|
28
|
+
enrollment.valid?
|
|
29
|
+
assert !enrollment.errors.on(field)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
[ :consented, :is_eligible,
|
|
36
|
+
:is_chosen, :is_complete, :terminated_participation,
|
|
37
|
+
:is_candidate ].each do |field|
|
|
38
|
+
|
|
39
|
+
# Making assumption that 12345 will NEVER be a valid value.
|
|
40
|
+
test "should NOT allow 12345 for #{field}" do
|
|
41
|
+
enrollment = Enrollment.new(field => 12345)
|
|
42
|
+
enrollment.valid?
|
|
43
|
+
assert enrollment.errors.on_attr_and_type?(field,:inclusion)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test "should allow nil for #{field}" do
|
|
47
|
+
enrollment = Enrollment.new(field => nil)
|
|
48
|
+
assert_nil enrollment.send(field)
|
|
49
|
+
enrollment.valid?
|
|
50
|
+
assert !enrollment.errors.on(field)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test "should allow all valid YNDK values for #{field}" do
|
|
54
|
+
enrollment = Enrollment.new
|
|
55
|
+
YNDK.valid_values.each do |value|
|
|
56
|
+
enrollment.send("#{field}=", value)
|
|
57
|
+
enrollment.valid?
|
|
58
|
+
assert !enrollment.errors.on(field)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
assert_should_create_default_object
|
|
67
|
+
assert_should_protect(:study_subject_id, :study_subject)
|
|
68
|
+
assert_should_not_require_attributes(
|
|
69
|
+
:refused_by_physician,
|
|
70
|
+
:refused_by_family,
|
|
71
|
+
:use_smp_future_rsrch,
|
|
72
|
+
:use_smp_future_cancer_rsrch,
|
|
73
|
+
:use_smp_future_other_rsrch,
|
|
74
|
+
:share_smp_with_others,
|
|
75
|
+
:contact_for_related_study,
|
|
76
|
+
:provide_saliva_smp,
|
|
77
|
+
:receive_study_findings,
|
|
78
|
+
:position,
|
|
79
|
+
:recruitment_priority,
|
|
80
|
+
# :able_to_locate,
|
|
81
|
+
:is_candidate,
|
|
82
|
+
:is_eligible,
|
|
83
|
+
:ineligible_reason_id,
|
|
84
|
+
:ineligible_reason_specify,
|
|
85
|
+
:refusal_reason_id,
|
|
86
|
+
:other_refusal_reason,
|
|
87
|
+
:is_chosen,
|
|
88
|
+
:reason_not_chosen,
|
|
89
|
+
:terminated_participation,
|
|
90
|
+
:terminated_reason,
|
|
91
|
+
:is_complete,
|
|
92
|
+
:completed_on,
|
|
93
|
+
:is_closed,
|
|
94
|
+
:reason_closed,
|
|
95
|
+
:notes,
|
|
96
|
+
:document_version_id )
|
|
97
|
+
assert_should_require_attribute_length(
|
|
98
|
+
:recruitment_priority,
|
|
99
|
+
:ineligible_reason_specify,
|
|
100
|
+
:other_refusal_reason,
|
|
101
|
+
:reason_not_chosen,
|
|
102
|
+
:terminated_reason,
|
|
103
|
+
:reason_closed,
|
|
104
|
+
:maximum => 250 )
|
|
105
|
+
|
|
106
|
+
assert_should_have_many(:follow_ups)
|
|
107
|
+
assert_should_have_many(:operational_events)
|
|
108
|
+
assert_should_belong_to(
|
|
109
|
+
:tracing_status,
|
|
110
|
+
:project_outcome,
|
|
111
|
+
:ineligible_reason,
|
|
112
|
+
:refusal_reason,
|
|
113
|
+
:document_version )
|
|
114
|
+
assert_should_require_attribute_length( :notes, :maximum => 65000 )
|
|
115
|
+
|
|
116
|
+
# using subjectless_enrollment so, this isn't true
|
|
117
|
+
# assert_should_initially_belong_to(:study_subject, :project)
|
|
118
|
+
assert_should_belong_to(:study_subject)
|
|
119
|
+
|
|
120
|
+
assert_should_initially_belong_to(:project)
|
|
121
|
+
assert_requires_complete_date(:completed_on, :consented_on)
|
|
122
|
+
assert_requires_past_date( :completed_on, :consented_on)
|
|
123
|
+
|
|
124
|
+
test "explicit Factory enrollment test" do
|
|
125
|
+
assert_difference('Project.count',1) {
|
|
126
|
+
assert_difference('StudySubject.count',1) {
|
|
127
|
+
assert_difference('Enrollment.count',2) { # this enrollment AND the subject's ccls enrollment
|
|
128
|
+
enrollment = Factory(:enrollment)
|
|
129
|
+
assert !enrollment.consented
|
|
130
|
+
assert_not_nil enrollment.project
|
|
131
|
+
assert_not_nil enrollment.study_subject
|
|
132
|
+
} } }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
test "explicit Factory subjectless_enrollment test" do
|
|
136
|
+
assert_difference('Project.count',1) {
|
|
137
|
+
assert_difference('StudySubject.count',0) {
|
|
138
|
+
assert_difference('Enrollment.count',1) {
|
|
139
|
+
enrollment = Factory(:subjectless_enrollment)
|
|
140
|
+
assert !enrollment.consented
|
|
141
|
+
assert_not_nil enrollment.project
|
|
142
|
+
assert_nil enrollment.study_subject
|
|
143
|
+
} } }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
test "explicit Factory consented_enrollment test" do
|
|
147
|
+
assert_difference('Project.count',1) {
|
|
148
|
+
assert_difference('StudySubject.count',1) {
|
|
149
|
+
assert_difference('Enrollment.count',2) { # this enrollment AND the subject's ccls enrollment
|
|
150
|
+
enrollment = Factory(:consented_enrollment)
|
|
151
|
+
assert enrollment.consented
|
|
152
|
+
assert_equal enrollment.consented, YNDK[:yes]
|
|
153
|
+
assert_not_nil enrollment.project
|
|
154
|
+
assert_not_nil enrollment.study_subject
|
|
155
|
+
} } }
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
test "explicit Factory declined_enrollment test" do
|
|
159
|
+
assert_difference('Project.count',1) {
|
|
160
|
+
assert_difference('StudySubject.count',1) {
|
|
161
|
+
assert_difference('Enrollment.count',2) { # this enrollment AND the subject's ccls enrollment
|
|
162
|
+
enrollment = Factory(:declined_enrollment)
|
|
163
|
+
assert enrollment.consented
|
|
164
|
+
assert_equal enrollment.consented, YNDK[:no]
|
|
165
|
+
assert_not_nil enrollment.project
|
|
166
|
+
assert_not_nil enrollment.study_subject
|
|
167
|
+
} } }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test "should require project" do
|
|
171
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
172
|
+
enrollment = create_subjectless_enrollment( :project => nil)
|
|
173
|
+
assert !enrollment.errors.on(:project)
|
|
174
|
+
assert enrollment.errors.on_attr_and_type?(:project_id,:blank)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
test "should require valid project" do
|
|
179
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
180
|
+
enrollment = create_subjectless_enrollment( :project_id => 0)
|
|
181
|
+
assert !enrollment.errors.on(:project_id)
|
|
182
|
+
assert enrollment.errors.on_attr_and_type?(:project,:blank)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
test "should require unique project_id scope study_subject_id" do
|
|
187
|
+
o = create_enrollment
|
|
188
|
+
assert_no_difference "Enrollment.count" do
|
|
189
|
+
enrollment = create_enrollment(:project => o.project,
|
|
190
|
+
:study_subject => o.study_subject)
|
|
191
|
+
assert enrollment.errors.on_attr_and_type?(:project_id, :taken)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# test "should require completed_on be in the past" do
|
|
196
|
+
# assert_difference( "Enrollment.count", 0 ) do
|
|
197
|
+
# enrollment = create_enrollment(
|
|
198
|
+
# :is_complete => YNDK[:yes],
|
|
199
|
+
# :completed_on => Date.tomorrow )
|
|
200
|
+
# # sometimes this fails during test:coverage?
|
|
201
|
+
# assert enrollment.errors.on(:completed_on)
|
|
202
|
+
# assert_match(/future/,
|
|
203
|
+
# enrollment.errors.on(:completed_on))
|
|
204
|
+
# end
|
|
205
|
+
# end
|
|
206
|
+
|
|
207
|
+
test "should require ineligible_reason if is_eligible == :no" do
|
|
208
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
209
|
+
enrollment = create_subjectless_enrollment(:is_eligible => YNDK[:no])
|
|
210
|
+
assert !enrollment.errors.on(:ineligible_reason)
|
|
211
|
+
assert enrollment.errors.on_attr_and_type?(:ineligible_reason_id,:blank)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
test "should require valid ineligible_reason if is_eligible == :no" do
|
|
215
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
216
|
+
enrollment = create_subjectless_enrollment(:is_eligible => YNDK[:no],
|
|
217
|
+
:ineligible_reason_id => 0)
|
|
218
|
+
assert !enrollment.errors.on(:ineligible_reason_id)
|
|
219
|
+
assert enrollment.errors.on_attr_and_type?(:ineligible_reason,:blank)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
[:yes,:dk,:nil].each do |yndk|
|
|
223
|
+
test "should NOT ALLOW ineligible_reason if is_eligible == #{yndk}" do
|
|
224
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
225
|
+
enrollment = create_subjectless_enrollment(:is_eligible => YNDK[yndk],
|
|
226
|
+
:ineligible_reason => Factory(:ineligible_reason) )
|
|
227
|
+
assert !enrollment.errors.on(:ineligible_reason)
|
|
228
|
+
assert enrollment.errors.on_attr_and_type?(:ineligible_reason_id,:present)
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
test "should require ineligible_reason_specify if " <<
|
|
234
|
+
"ineligible_reason == other" do
|
|
235
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
236
|
+
enrollment = create_subjectless_enrollment(
|
|
237
|
+
:is_eligible => YNDK[:no],
|
|
238
|
+
:ineligible_reason => IneligibleReason['other'] )
|
|
239
|
+
assert enrollment.errors.on(:ineligible_reason_specify)
|
|
240
|
+
assert enrollment.errors.on_attr_and_type?(:ineligible_reason_specify,:blank)
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
test "should ALLOW ineligible_reason_specify if " <<
|
|
244
|
+
"ineligible_reason != other" do
|
|
245
|
+
assert_difference( "Enrollment.count", 1 ) do
|
|
246
|
+
enrollment = create_subjectless_enrollment(
|
|
247
|
+
:is_eligible => YNDK[:no],
|
|
248
|
+
:ineligible_reason => Factory(:ineligible_reason),
|
|
249
|
+
:ineligible_reason_specify => 'blah blah blah' )
|
|
250
|
+
assert !enrollment.errors.on(:ineligible_reason_specify)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
[:yes,:dk,:nil].each do |yndk|
|
|
254
|
+
test "should NOT ALLOW ineligible_reason_specify if " <<
|
|
255
|
+
"is_eligible == #{yndk}" do
|
|
256
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
257
|
+
enrollment = create_subjectless_enrollment(
|
|
258
|
+
:is_eligible => YNDK[yndk],
|
|
259
|
+
:ineligible_reason => Factory(:ineligible_reason),
|
|
260
|
+
:ineligible_reason_specify => 'blah blah blah' )
|
|
261
|
+
assert enrollment.errors.on(:ineligible_reason_specify)
|
|
262
|
+
assert enrollment.errors.on_attr_and_type?(:ineligible_reason_specify,:present)
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
test "should require reason_not_chosen if is_chosen == :no" do
|
|
269
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
270
|
+
enrollment = create_subjectless_enrollment(:is_chosen => YNDK[:no])
|
|
271
|
+
assert enrollment.errors.on(:reason_not_chosen)
|
|
272
|
+
assert enrollment.errors.on_attr_and_type?(:reason_not_chosen,:blank)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
[:yes,:dk,:nil].each do |yndk|
|
|
276
|
+
test "should NOT ALLOW reason_not_chosen if is_chosen == #{yndk}" do
|
|
277
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
278
|
+
enrollment = create_subjectless_enrollment(:is_chosen => YNDK[yndk],
|
|
279
|
+
:reason_not_chosen => "blah blah blah")
|
|
280
|
+
assert enrollment.errors.on(:reason_not_chosen)
|
|
281
|
+
assert enrollment.errors.on_attr_and_type?(:reason_not_chosen,:present)
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
test "should require refusal_reason if consented == :no" do
|
|
288
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
289
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:no])
|
|
290
|
+
assert !enrollment.errors.on(:refusal_reason)
|
|
291
|
+
assert enrollment.errors.on_attr_and_type?(:refusal_reason_id,:blank)
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
test "should require valid refusal_reason if consented == :no" do
|
|
295
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
296
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:no],
|
|
297
|
+
:refusal_reason_id => 0)
|
|
298
|
+
assert !enrollment.errors.on(:refusal_reason_id)
|
|
299
|
+
assert enrollment.errors.on_attr_and_type?(:refusal_reason,:blank)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
[:yes,:dk,:nil].each do |yndk|
|
|
303
|
+
test "should NOT ALLOW refusal_reason if consented == #{yndk}" do
|
|
304
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
305
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[yndk],
|
|
306
|
+
:refusal_reason => Factory(:refusal_reason))
|
|
307
|
+
assert !enrollment.errors.on(:refusal_reason)
|
|
308
|
+
assert enrollment.errors.on_attr_and_type?(:refusal_reason_id,:present)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
test "should require other_refusal_reason if " <<
|
|
314
|
+
"refusal_reason == other" do
|
|
315
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
316
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:no],
|
|
317
|
+
:refusal_reason => RefusalReason['other'] )
|
|
318
|
+
assert enrollment.errors.on(:other_refusal_reason)
|
|
319
|
+
assert enrollment.errors.on_attr_and_type?(:other_refusal_reason,:blank)
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
test "should ALLOW other_refusal_reason if " <<
|
|
323
|
+
"refusal_reason != other" do
|
|
324
|
+
assert_difference( "Enrollment.count", 1 ) do
|
|
325
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:no],
|
|
326
|
+
:consented_on => Date.today,
|
|
327
|
+
:refusal_reason => Factory(:refusal_reason),
|
|
328
|
+
:other_refusal_reason => 'asdfasdf' )
|
|
329
|
+
assert !enrollment.errors.on(:other_refusal_reason)
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
[:yes,:dk,:nil].each do |yndk|
|
|
333
|
+
test "should NOT ALLOW other_refusal_reason if "<<
|
|
334
|
+
"consented == #{yndk}" do
|
|
335
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
336
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[yndk],
|
|
337
|
+
:refusal_reason => Factory(:refusal_reason),
|
|
338
|
+
:other_refusal_reason => 'asdfasdf' )
|
|
339
|
+
assert enrollment.errors.on(:other_refusal_reason)
|
|
340
|
+
assert enrollment.errors.on_attr_and_type?(:other_refusal_reason,:present)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
[:yes,:no].each do |yndk|
|
|
347
|
+
test "should require consented_on if consented == #{yndk}" do
|
|
348
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
349
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[yndk],
|
|
350
|
+
:consented_on => nil)
|
|
351
|
+
assert enrollment.errors.on_attr_and_type?(:consented_on,:blank)
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
[:dk,:nil].each do |yndk|
|
|
356
|
+
test "should NOT ALLOW consented_on if consented == #{yndk}" do
|
|
357
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
358
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[yndk],
|
|
359
|
+
:consented_on => Date.today)
|
|
360
|
+
assert enrollment.errors.on(:consented_on)
|
|
361
|
+
assert enrollment.errors.on_attr_and_type?(:consented_on,:present)
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
test "should require terminated_reason if " <<
|
|
368
|
+
"terminated_participation == :yes" do
|
|
369
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
370
|
+
enrollment = create_subjectless_enrollment(:terminated_participation => YNDK[:yes])
|
|
371
|
+
assert enrollment.errors.on(:terminated_reason)
|
|
372
|
+
assert enrollment.errors.on_attr_and_type?(:terminated_reason,:blank)
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
[:no,:dk,:nil].each do |yndk|
|
|
376
|
+
test "should NOT ALLOW terminated_reason if " <<
|
|
377
|
+
"terminated_participation == #{yndk}" do
|
|
378
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
379
|
+
enrollment = create_subjectless_enrollment(
|
|
380
|
+
:terminated_participation => YNDK[yndk],
|
|
381
|
+
:terminated_reason => 'some bogus reason')
|
|
382
|
+
assert enrollment.errors.on(:terminated_reason)
|
|
383
|
+
assert enrollment.errors.on_attr_and_type?(:terminated_reason,:present)
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
test "should require completed_on if is_complete == :yes" do
|
|
390
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
391
|
+
enrollment = create_subjectless_enrollment(:is_complete => YNDK[:yes])
|
|
392
|
+
assert enrollment.errors.on(:completed_on)
|
|
393
|
+
assert enrollment.errors.on_attr_and_type?(:completed_on,:blank)
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
[:no,:dk,:nil].each do |yndk|
|
|
397
|
+
test "should NOT ALLOW completed_on if is_complete == #{yndk}" do
|
|
398
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
399
|
+
enrollment = create_subjectless_enrollment(:is_complete => YNDK[yndk],
|
|
400
|
+
:completed_on => Date.today)
|
|
401
|
+
assert enrollment.errors.on(:completed_on)
|
|
402
|
+
assert enrollment.errors.on_attr_and_type?(:completed_on,:present)
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
[:dk,:nil].each do |yndk|
|
|
409
|
+
test "should NOT ALLOW document_version_id if consented == #{yndk}" do
|
|
410
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
411
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[yndk],
|
|
412
|
+
:document_version => Factory(:document_version) )
|
|
413
|
+
assert !enrollment.errors.on(:document_version)
|
|
414
|
+
assert enrollment.errors.on_attr_and_type?(:document_version_id,:present)
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
test "should allow document_version_id if consented == :yes" do
|
|
419
|
+
assert_difference( "Enrollment.count", 1 ) do
|
|
420
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:yes],
|
|
421
|
+
:consented_on => Date.today,
|
|
422
|
+
:document_version => Factory(:document_version) )
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
test "should allow document_version_id if consented == :no" do
|
|
426
|
+
assert_difference( "Enrollment.count", 1 ) do
|
|
427
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:no],
|
|
428
|
+
:consented_on => Date.today,
|
|
429
|
+
:refusal_reason => Factory(:refusal_reason),
|
|
430
|
+
:document_version => Factory(:document_version) )
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
test "should require valid document_version if given" do
|
|
434
|
+
assert_difference( "Enrollment.count", 0 ) do
|
|
435
|
+
enrollment = create_subjectless_enrollment(:consented => YNDK[:yes],
|
|
436
|
+
:consented_on => Date.today,
|
|
437
|
+
:document_version_id => 0 )
|
|
438
|
+
assert !enrollment.errors.on(:document_version_id)
|
|
439
|
+
assert enrollment.errors.on_attr_and_type?(:document_version,:blank)
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
test "should create operational event when enrollment complete" do
|
|
445
|
+
enrollment = create_subjectless_enrollment(
|
|
446
|
+
:completed_on => nil,
|
|
447
|
+
:is_complete => YNDK[:no])
|
|
448
|
+
# arbitrary past date
|
|
449
|
+
past_date = Date.parse('Jan 15 2003')
|
|
450
|
+
assert_difference('OperationalEvent.count',1) do
|
|
451
|
+
enrollment.update_attributes(
|
|
452
|
+
:completed_on => past_date,
|
|
453
|
+
:is_complete => YNDK[:yes])
|
|
454
|
+
end
|
|
455
|
+
oe = enrollment.operational_events.find(:last,:order => 'id ASC')
|
|
456
|
+
assert_equal 'complete', oe.operational_event_type.key
|
|
457
|
+
assert_equal past_date, oe.occurred_on
|
|
458
|
+
assert_equal enrollment.study_subject_id, oe.enrollment.study_subject_id
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
test "should create operational event when enrollment complete UNSET" do
|
|
462
|
+
# arbitrary past date
|
|
463
|
+
past_date = Date.parse('Jan 15 2003')
|
|
464
|
+
enrollment = nil
|
|
465
|
+
assert_difference('OperationalEvent.count',1) do
|
|
466
|
+
enrollment = create_subjectless_enrollment(
|
|
467
|
+
:completed_on => past_date,
|
|
468
|
+
:is_complete => YNDK[:yes])
|
|
469
|
+
end
|
|
470
|
+
oe = enrollment.operational_events.find(:last,:order => 'id ASC')
|
|
471
|
+
assert_equal 'complete', oe.operational_event_type.key
|
|
472
|
+
assert_difference('OperationalEvent.count',1) do
|
|
473
|
+
enrollment.update_attributes(
|
|
474
|
+
:is_complete => YNDK[:no],
|
|
475
|
+
:completed_on => nil)
|
|
476
|
+
end
|
|
477
|
+
oe = enrollment.operational_events.find(:last,:order => 'id ASC')
|
|
478
|
+
assert_equal 'reopened', oe.operational_event_type.key
|
|
479
|
+
assert_equal Date.today, oe.occurred_on
|
|
480
|
+
assert_equal enrollment.study_subject_id, oe.enrollment.study_subject_id
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
test "should create subjectConsents operational event if consent changes to yes" do
|
|
484
|
+
enrollment = Factory(:subjectless_enrollment)
|
|
485
|
+
assert_nil enrollment.consented
|
|
486
|
+
assert_difference("Enrollment.find(#{enrollment.id}).operational_events.count",1){
|
|
487
|
+
enrollment.update_attributes(:consented => YNDK[:yes],
|
|
488
|
+
:consented_on => Date.today )
|
|
489
|
+
}
|
|
490
|
+
enrollment.reload
|
|
491
|
+
assert_equal enrollment.consented, YNDK[:yes]
|
|
492
|
+
assert_equal enrollment.consented_on, Date.today
|
|
493
|
+
consented_event = enrollment.operational_events.find(:first,:conditions => {
|
|
494
|
+
:operational_event_type_id => OperationalEventType['subjectConsents'].id })
|
|
495
|
+
assert_not_nil consented_event
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
test "should not create subjectConsents operational event if consent doesn't change" do
|
|
499
|
+
enrollment = Factory(:consented_enrollment)
|
|
500
|
+
assert_not_nil enrollment.consented
|
|
501
|
+
assert_difference("Enrollment.find(#{enrollment.id}).operational_events.count",0){
|
|
502
|
+
enrollment.update_attributes(:consented => YNDK[:yes],
|
|
503
|
+
:consented_on => Date.today )
|
|
504
|
+
}
|
|
505
|
+
enrollment.reload
|
|
506
|
+
assert_equal enrollment.consented, YNDK[:yes]
|
|
507
|
+
assert_equal enrollment.consented_on, Date.today
|
|
508
|
+
consented_event = enrollment.operational_events.find(:first,:conditions => {
|
|
509
|
+
:operational_event_type_id => OperationalEventType['subjectConsents'].id })
|
|
510
|
+
assert_not_nil consented_event
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
test "should create subjectDeclines operational event if consent changes to no" do
|
|
514
|
+
enrollment = Factory(:subjectless_enrollment)
|
|
515
|
+
assert_nil enrollment.consented
|
|
516
|
+
assert_difference("Enrollment.find(#{enrollment.id}).operational_events.count",1){
|
|
517
|
+
enrollment.update_attributes(:consented => YNDK[:no],
|
|
518
|
+
:refusal_reason => Factory(:refusal_reason),
|
|
519
|
+
:consented_on => Date.today )
|
|
520
|
+
}
|
|
521
|
+
enrollment.reload
|
|
522
|
+
assert_equal enrollment.consented, YNDK[:no]
|
|
523
|
+
assert_equal enrollment.consented_on, Date.today
|
|
524
|
+
declined_event = enrollment.operational_events.find(:first,:conditions => {
|
|
525
|
+
:operational_event_type_id => OperationalEventType['subjectDeclines'].id })
|
|
526
|
+
assert_not_nil declined_event
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
test "should not create subjectDeclines operational event if consent doesn't change" do
|
|
530
|
+
enrollment = Factory(:declined_enrollment)
|
|
531
|
+
assert_not_nil enrollment.consented
|
|
532
|
+
assert_difference("Enrollment.find(#{enrollment.id}).operational_events.count",0){
|
|
533
|
+
enrollment.update_attributes(:consented => YNDK[:no],
|
|
534
|
+
:consented_on => Date.today )
|
|
535
|
+
}
|
|
536
|
+
enrollment.reload
|
|
537
|
+
assert_equal enrollment.consented, YNDK[:no]
|
|
538
|
+
assert_equal enrollment.consented_on, Date.today
|
|
539
|
+
declined_event = enrollment.operational_events.find(:first,:conditions => {
|
|
540
|
+
:operational_event_type_id => OperationalEventType['subjectDeclines'].id })
|
|
541
|
+
assert_not_nil declined_event
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
test "should have consented named_scope" do
|
|
545
|
+
assert_equal [], Enrollment.consented
|
|
546
|
+
Factory(:enrollment)
|
|
547
|
+
assert_equal [], Enrollment.consented
|
|
548
|
+
enrollment = Factory(:consented_enrollment)
|
|
549
|
+
assert_equal [enrollment], Enrollment.consented
|
|
550
|
+
Factory(:enrollment)
|
|
551
|
+
assert_equal [enrollment], Enrollment.consented
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
protected
|
|
555
|
+
|
|
556
|
+
# MUST define this method so can use the alias_method below.
|
|
557
|
+
# Or could just define create_object. Either way.
|
|
558
|
+
def create_subjectless_enrollment(options={})
|
|
559
|
+
enrollment = Factory.build(:subjectless_enrollment,options)
|
|
560
|
+
enrollment.save
|
|
561
|
+
enrollment
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
# create_object is used in the basic assertions,
|
|
565
|
+
# but it creates a subject which creates an enrollment and operational_event
|
|
566
|
+
# so if I create a subjectless enrollment, they work
|
|
567
|
+
alias_method :create_object, :create_subjectless_enrollment
|
|
568
|
+
|
|
569
|
+
# def create_enrollment(options={})
|
|
570
|
+
# enrollment = Factory.build(:enrollment,options)
|
|
571
|
+
# enrollment.save
|
|
572
|
+
# enrollment
|
|
573
|
+
# end
|
|
574
|
+
|
|
575
|
+
end
|