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,770 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Ccls::StudySubjectTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
[ :mom_is_biomom, :dad_is_biodad ].each do |field|
|
|
6
|
+
|
|
7
|
+
# Making assumption that 12345 will NEVER be a valid value.
|
|
8
|
+
test "should NOT allow 12345 for #{field}" do
|
|
9
|
+
study_subject = StudySubject.new(field => 12345)
|
|
10
|
+
study_subject.valid?
|
|
11
|
+
assert study_subject.errors.on_attr_and_type?(field,:inclusion)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "should allow nil for #{field}" do
|
|
15
|
+
study_subject = StudySubject.new(field => nil)
|
|
16
|
+
assert_nil study_subject.send(field)
|
|
17
|
+
study_subject.valid?
|
|
18
|
+
assert !study_subject.errors.on(field)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "should allow all valid YNDK values for #{field}" do
|
|
22
|
+
study_subject = StudySubject.new
|
|
23
|
+
YNDK.valid_values.each do |value|
|
|
24
|
+
study_subject.send("#{field}=", value)
|
|
25
|
+
study_subject.valid?
|
|
26
|
+
assert !study_subject.errors.on(field)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_should_create_default_object
|
|
33
|
+
|
|
34
|
+
# Cannot include enrollments here due to the creation of one
|
|
35
|
+
# during the creation of a study_subject
|
|
36
|
+
# Should create custom check, but this is indirectly tested
|
|
37
|
+
# in the creation of the enrollment so not really needed.
|
|
38
|
+
# :enrollments,
|
|
39
|
+
|
|
40
|
+
assert_should_have_many( :samples,
|
|
41
|
+
:gift_cards, :phone_numbers, :interviews, :bc_requests )
|
|
42
|
+
assert_should_initially_belong_to( :subject_type, :vital_status )
|
|
43
|
+
assert_should_have_one( :home_exposure_response, :homex_outcome )
|
|
44
|
+
assert_should_habtm(:analyses)
|
|
45
|
+
assert_should_belong_to( :guardian_relationship, :class_name => 'SubjectRelationship' )
|
|
46
|
+
|
|
47
|
+
assert_should_not_require_attributes( :vital_status_id, :hispanicity_id,
|
|
48
|
+
:mom_is_biomom, :dad_is_biodad,
|
|
49
|
+
:mother_hispanicity_id, :father_hispanicity_id,
|
|
50
|
+
:mother_hispanicity_mex, :father_hispanicity_mex,
|
|
51
|
+
:reference_date, :mother_yrs_educ, :father_yrs_educ,
|
|
52
|
+
:birth_type, :birth_county, :is_duplicate_of,
|
|
53
|
+
:first_name, :last_name,
|
|
54
|
+
:died_on, :birth_year,
|
|
55
|
+
:birth_city, :birth_state, :birth_country,
|
|
56
|
+
:mother_first_name, :mother_middle_name, :mother_maiden_name, :mother_last_name,
|
|
57
|
+
:father_first_name, :father_middle_name, :father_last_name,
|
|
58
|
+
:guardian_first_name, :guardian_middle_name, :guardian_last_name,
|
|
59
|
+
:guardian_relationship_other, :email,
|
|
60
|
+
:middle_name, :maiden_name,
|
|
61
|
+
:mother_race_other, :father_race_other,
|
|
62
|
+
:generational_suffix, :father_generational_suffix,
|
|
63
|
+
:case_control_type,
|
|
64
|
+
:ssn,
|
|
65
|
+
:subjectid,
|
|
66
|
+
:lab_no,
|
|
67
|
+
:related_childid,
|
|
68
|
+
:related_case_childid,
|
|
69
|
+
:state_id_no,
|
|
70
|
+
:state_registrar_no,
|
|
71
|
+
:local_registrar_no,
|
|
72
|
+
:matchingid,
|
|
73
|
+
:gbid,
|
|
74
|
+
:lab_no_wiemels,
|
|
75
|
+
:accession_no,
|
|
76
|
+
:idno_wiemels,
|
|
77
|
+
:is_matched,
|
|
78
|
+
:familyid )
|
|
79
|
+
|
|
80
|
+
assert_should_require_attributes( :dob )
|
|
81
|
+
|
|
82
|
+
assert_should_require_unique_attributes( :email,
|
|
83
|
+
:state_id_no,
|
|
84
|
+
:state_registrar_no,
|
|
85
|
+
:local_registrar_no,
|
|
86
|
+
:gbid,
|
|
87
|
+
:lab_no_wiemels,
|
|
88
|
+
:accession_no,
|
|
89
|
+
:idno_wiemels )
|
|
90
|
+
|
|
91
|
+
assert_requires_complete_date( :reference_date, :dob, :died_on )
|
|
92
|
+
assert_requires_past_date( :dob )
|
|
93
|
+
|
|
94
|
+
assert_should_require_attributes_not_nil( :do_not_contact, :sex )
|
|
95
|
+
|
|
96
|
+
assert_should_require_attribute_length(
|
|
97
|
+
:first_name, :middle_name, :maiden_name, :last_name,
|
|
98
|
+
:mother_first_name, :mother_middle_name, :mother_maiden_name, :mother_last_name,
|
|
99
|
+
:father_first_name, :father_middle_name, :father_last_name,
|
|
100
|
+
:guardian_first_name, :guardian_middle_name, :guardian_last_name,
|
|
101
|
+
:guardian_relationship_other,
|
|
102
|
+
:birth_city, :birth_state, :birth_country,
|
|
103
|
+
:mother_race_other, :father_race_other,
|
|
104
|
+
:state_id_no,
|
|
105
|
+
:state_registrar_no,
|
|
106
|
+
:local_registrar_no,
|
|
107
|
+
:lab_no,
|
|
108
|
+
:related_childid,
|
|
109
|
+
:related_case_childid,
|
|
110
|
+
:maximum => 250 )
|
|
111
|
+
|
|
112
|
+
assert_should_require_attribute_length( :gbid, :maximum => 26 )
|
|
113
|
+
assert_should_require_attribute_length( :lab_no_wiemels, :accession_no,
|
|
114
|
+
:maximum => 25 )
|
|
115
|
+
assert_should_require_attribute_length( :generational_suffix,
|
|
116
|
+
:father_generational_suffix, :childidwho, :idno_wiemels,
|
|
117
|
+
:maximum => 10 )
|
|
118
|
+
assert_should_require_attribute_length( :icf_master_id, :maximum => 9 )
|
|
119
|
+
assert_should_require_attribute_length( :newid, :maximum => 6 )
|
|
120
|
+
assert_should_require_attribute_length( :birth_year, :maximum => 4 )
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# assert_should_require :hospital_no
|
|
124
|
+
# assert_should_not_require :hospital_no
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
assert_should_protect_attributes(
|
|
128
|
+
:studyid,
|
|
129
|
+
:studyid_nohyphen,
|
|
130
|
+
:studyid_intonly_nohyphen,
|
|
131
|
+
:familyid,
|
|
132
|
+
:childid,
|
|
133
|
+
:subjectid,
|
|
134
|
+
:patid )
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
test "explicit Factory study_subject test" do
|
|
143
|
+
assert_difference('VitalStatus.count',1) {
|
|
144
|
+
assert_difference('SubjectType.count',1) {
|
|
145
|
+
assert_difference('StudySubject.count',1) {
|
|
146
|
+
study_subject = Factory(:study_subject)
|
|
147
|
+
assert_not_nil study_subject.subject_type
|
|
148
|
+
assert_not_nil study_subject.vital_status
|
|
149
|
+
assert_not_nil study_subject.sex
|
|
150
|
+
} } }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
test "explicit Factory case study_subject test" do
|
|
154
|
+
assert_difference('StudySubject.count',1) {
|
|
155
|
+
study_subject = Factory(:case_study_subject)
|
|
156
|
+
assert_equal study_subject.subject_type, SubjectType['Case']
|
|
157
|
+
}
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
test "explicit Factory control study_subject test" do
|
|
161
|
+
assert_difference('StudySubject.count',1) {
|
|
162
|
+
study_subject = Factory(:control_study_subject)
|
|
163
|
+
assert_equal study_subject.subject_type, SubjectType['Control']
|
|
164
|
+
}
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
test "explicit Factory mother study_subject test" do
|
|
168
|
+
assert_difference('StudySubject.count',1) {
|
|
169
|
+
s = Factory(:mother_study_subject)
|
|
170
|
+
assert_equal s.subject_type, SubjectType['Mother']
|
|
171
|
+
assert_equal s.sex, 'F'
|
|
172
|
+
assert_nil s.studyid
|
|
173
|
+
assert_not_nil s.studyid_to_s
|
|
174
|
+
assert_equal 'n/a', s.studyid_to_s
|
|
175
|
+
}
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
test "explicit Factory complete case study subject build test" do
|
|
179
|
+
assert_difference('Patient.count',0) {
|
|
180
|
+
assert_difference('StudySubject.count',0) {
|
|
181
|
+
s = Factory.build(:complete_case_study_subject)
|
|
182
|
+
} }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
test "explicit Factory complete case study subject test" do
|
|
186
|
+
assert_difference('Patient.count',1) {
|
|
187
|
+
assert_difference('StudySubject.count',1) {
|
|
188
|
+
s = Factory(:complete_case_study_subject)
|
|
189
|
+
assert_equal s.subject_type, SubjectType['Case']
|
|
190
|
+
assert_equal s.case_control_type, 'C'
|
|
191
|
+
assert_equal s.orderno, 0
|
|
192
|
+
assert_not_nil s.childid
|
|
193
|
+
assert_not_nil s.patid
|
|
194
|
+
assert_not_nil s.organization_id
|
|
195
|
+
assert_not_nil s.studyid
|
|
196
|
+
assert_not_nil s.studyid
|
|
197
|
+
assert_match /\d{4}-C-0/, s.studyid
|
|
198
|
+
# New sequencing make the value of this relatively unpredictable
|
|
199
|
+
# assert_equal s.organization_id, Hospital.first.organization_id
|
|
200
|
+
} }
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
test "explicit Factory complete waivered case study subject test" do
|
|
204
|
+
assert_difference('Patient.count',1) {
|
|
205
|
+
assert_difference('StudySubject.count',1) {
|
|
206
|
+
s = Factory(:complete_waivered_case_study_subject)
|
|
207
|
+
assert_equal s.subject_type, SubjectType['Case']
|
|
208
|
+
assert_equal s.case_control_type, 'C'
|
|
209
|
+
assert_equal s.orderno, 0
|
|
210
|
+
assert_not_nil s.childid
|
|
211
|
+
assert_not_nil s.patid
|
|
212
|
+
assert_not_nil s.organization_id
|
|
213
|
+
assert s.organization.hospital.has_irb_waiver
|
|
214
|
+
} }
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
test "explicit Factory complete nonwaivered case study subject test" do
|
|
218
|
+
assert_difference('Patient.count',1) {
|
|
219
|
+
assert_difference('StudySubject.count',1) {
|
|
220
|
+
s = Factory(:complete_nonwaivered_case_study_subject)
|
|
221
|
+
assert_equal s.subject_type, SubjectType['Case']
|
|
222
|
+
assert_equal s.case_control_type, 'C'
|
|
223
|
+
assert_equal s.orderno, 0
|
|
224
|
+
assert_not_nil s.childid
|
|
225
|
+
assert_not_nil s.patid
|
|
226
|
+
assert_not_nil s.organization_id
|
|
227
|
+
assert !s.organization.hospital.has_irb_waiver
|
|
228
|
+
} }
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
test "should require subject_type" do
|
|
232
|
+
assert_difference( "StudySubject.count", 0 ) do
|
|
233
|
+
study_subject = create_study_subject( :subject_type => nil)
|
|
234
|
+
assert !study_subject.errors.on(:subject_type)
|
|
235
|
+
assert study_subject.errors.on_attr_and_type?(:subject_type_id,:blank)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
test "should require valid subject_type" do
|
|
240
|
+
assert_difference( "StudySubject.count", 0 ) do
|
|
241
|
+
study_subject = create_study_subject( :subject_type_id => 0)
|
|
242
|
+
assert !study_subject.errors.on(:subject_type_id)
|
|
243
|
+
assert study_subject.errors.on_attr_and_type?(:subject_type,:blank)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
test "should require sex be either M, F or DK" do
|
|
248
|
+
assert_difference( "StudySubject.count", 0 ) {
|
|
249
|
+
study_subject = create_study_subject(:sex => 'X')
|
|
250
|
+
assert study_subject.errors.on_attr_and_type?(:sex,:inclusion)
|
|
251
|
+
}
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
test "should require sex with custom message" do
|
|
255
|
+
assert_difference( "StudySubject.count", 0 ) do
|
|
256
|
+
study_subject = create_study_subject( :sex => nil )
|
|
257
|
+
assert study_subject.errors.on_attr_and_type?(:sex,:blank)
|
|
258
|
+
assert_match /No sex has been chosen/,
|
|
259
|
+
study_subject.errors.full_messages.to_sentence
|
|
260
|
+
assert_no_match /Sex can't be blank/i,
|
|
261
|
+
study_subject.errors.full_messages.to_sentence
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
test "create_control_study_subject should not create a subject type" do
|
|
266
|
+
assert_difference( 'SubjectType.count', 0 ){
|
|
267
|
+
assert_difference( "StudySubject.count", 1 ) {
|
|
268
|
+
study_subject = create_control_study_subject
|
|
269
|
+
assert !study_subject.is_case?
|
|
270
|
+
assert !study_subject.new_record?,
|
|
271
|
+
"#{study_subject.errors.full_messages.to_sentence}"
|
|
272
|
+
} }
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
test "create_case_study_subject should not create a subject type" do
|
|
276
|
+
assert_difference( 'SubjectType.count', 0 ){
|
|
277
|
+
assert_difference( "StudySubject.count", 1 ) {
|
|
278
|
+
study_subject = create_case_study_subject
|
|
279
|
+
assert study_subject.is_case?
|
|
280
|
+
assert !study_subject.new_record?,
|
|
281
|
+
"#{study_subject.errors.full_messages.to_sentence}"
|
|
282
|
+
} }
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
test "should create study_subject" do
|
|
286
|
+
assert_difference( 'VitalStatus.count', 1 ){
|
|
287
|
+
assert_difference( 'SubjectType.count', 1 ){
|
|
288
|
+
assert_difference( "StudySubject.count", 1 ) {
|
|
289
|
+
study_subject = create_study_subject
|
|
290
|
+
assert !study_subject.new_record?,
|
|
291
|
+
"#{study_subject.errors.full_messages.to_sentence}"
|
|
292
|
+
} } }
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
test "should create study_subject and accept_nested_attributes_for phone_numbers" do
|
|
296
|
+
assert_difference( 'PhoneNumber.count', 1) {
|
|
297
|
+
assert_difference( "StudySubject.count", 1 ) {
|
|
298
|
+
study_subject = create_study_subject(
|
|
299
|
+
:phone_numbers_attributes => [Factory.attributes_for(:phone_number,
|
|
300
|
+
:phone_type_id => PhoneType['home'].id )])
|
|
301
|
+
assert !study_subject.new_record?,
|
|
302
|
+
"#{study_subject.errors.full_messages.to_sentence}"
|
|
303
|
+
} }
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
test "should create study_subject and ignore blank phone_number" do
|
|
307
|
+
assert_difference( 'PhoneNumber.count', 0) {
|
|
308
|
+
assert_difference( "StudySubject.count", 1 ) {
|
|
309
|
+
study_subject = create_study_subject(
|
|
310
|
+
:phone_numbers_attributes => [Factory.attributes_for(:phone_number,
|
|
311
|
+
:phone_number => '' )])
|
|
312
|
+
assert !study_subject.new_record?,
|
|
313
|
+
"#{study_subject.errors.full_messages.to_sentence}"
|
|
314
|
+
} }
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
test "should belong to vital_status" do
|
|
318
|
+
study_subject = create_study_subject(:vital_status => nil)
|
|
319
|
+
assert_nil study_subject.vital_status
|
|
320
|
+
study_subject.vital_status = Factory(:vital_status)
|
|
321
|
+
assert_not_nil study_subject.vital_status
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# test "should NOT destroy dust_kit with study_subject" do
|
|
325
|
+
# study_subject = create_study_subject
|
|
326
|
+
# Factory(:dust_kit, :study_subject => study_subject)
|
|
327
|
+
# assert_difference('StudySubject.count',-1) {
|
|
328
|
+
# assert_difference('DustKit.count',0) {
|
|
329
|
+
# study_subject.destroy
|
|
330
|
+
# } }
|
|
331
|
+
# end
|
|
332
|
+
|
|
333
|
+
#
|
|
334
|
+
# The dependency relationships are left undefined for most models.
|
|
335
|
+
# Because of this, associated records are neither nullfied nor destroyed
|
|
336
|
+
# when the associated models is destroyed.
|
|
337
|
+
#
|
|
338
|
+
|
|
339
|
+
test "should NOT destroy bc_requests with study_subject" do
|
|
340
|
+
assert_difference('StudySubject.count',1) {
|
|
341
|
+
assert_difference('BcRequest.count',1) {
|
|
342
|
+
@study_subject = Factory(:study_subject)
|
|
343
|
+
Factory(:bc_request, :study_subject => @study_subject)
|
|
344
|
+
} }
|
|
345
|
+
assert_difference('StudySubject.count',-1) {
|
|
346
|
+
assert_difference('BcRequest.count',0) {
|
|
347
|
+
@study_subject.destroy
|
|
348
|
+
} }
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
test "should NOT destroy gift_cards with study_subject" do
|
|
352
|
+
assert_difference('StudySubject.count',1) {
|
|
353
|
+
assert_difference('GiftCard.count',1) {
|
|
354
|
+
@study_subject = Factory(:study_subject)
|
|
355
|
+
Factory(:gift_card, :study_subject => @study_subject)
|
|
356
|
+
} }
|
|
357
|
+
assert_difference('StudySubject.count',-1) {
|
|
358
|
+
assert_difference('GiftCard.count',0) {
|
|
359
|
+
@study_subject.destroy
|
|
360
|
+
} }
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
test "should NOT destroy home_exposure_response with study_subject" do
|
|
364
|
+
assert_difference('StudySubject.count',1) {
|
|
365
|
+
assert_difference('HomeExposureResponse.count',1) {
|
|
366
|
+
@study_subject = Factory(:home_exposure_response).study_subject
|
|
367
|
+
} }
|
|
368
|
+
assert_difference('StudySubject.count',-1) {
|
|
369
|
+
assert_difference('HomeExposureResponse.count',0) {
|
|
370
|
+
@study_subject.destroy
|
|
371
|
+
} }
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
test "should NOT destroy phone_numbers with study_subject" do
|
|
375
|
+
assert_difference('StudySubject.count',1) {
|
|
376
|
+
assert_difference('PhoneNumber.count',1) {
|
|
377
|
+
@study_subject = Factory(:phone_number).study_subject
|
|
378
|
+
} }
|
|
379
|
+
assert_difference('StudySubject.count',-1) {
|
|
380
|
+
assert_difference('PhoneNumber.count',0) {
|
|
381
|
+
@study_subject.destroy
|
|
382
|
+
} }
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
test "should NOT destroy samples with study_subject" do
|
|
386
|
+
assert_difference('StudySubject.count',1) {
|
|
387
|
+
assert_difference('Sample.count',1) {
|
|
388
|
+
@study_subject = Factory(:sample).study_subject
|
|
389
|
+
} }
|
|
390
|
+
assert_difference('StudySubject.count',-1) {
|
|
391
|
+
assert_difference('Sample.count',0) {
|
|
392
|
+
@study_subject.destroy
|
|
393
|
+
} }
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# test "should have many samples through enrollments" do
|
|
397
|
+
# assert_difference('StudySubject.count',1) {
|
|
398
|
+
# assert_difference('Enrollment.count',2) {
|
|
399
|
+
# assert_difference('Sample.count',1) {
|
|
400
|
+
# sample = Factory(:sample)
|
|
401
|
+
## subject = sample.enrollment.study_subject
|
|
402
|
+
# subject = sample.study_subject
|
|
403
|
+
# assert subject.samples.include?(sample)
|
|
404
|
+
# } } }
|
|
405
|
+
# end
|
|
406
|
+
|
|
407
|
+
test "should have and belong to many analyses" do
|
|
408
|
+
study_subject = create_study_subject
|
|
409
|
+
assert_equal 0, study_subject.analyses.length
|
|
410
|
+
study_subject.analyses << Factory(:analysis)
|
|
411
|
+
assert_equal 1, study_subject.reload.analyses.length
|
|
412
|
+
study_subject.analyses << Factory(:analysis)
|
|
413
|
+
assert_equal 2, study_subject.reload.analyses.length
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
test "should return subject_type description for string" do
|
|
417
|
+
study_subject = create_study_subject
|
|
418
|
+
assert_equal study_subject.subject_type.description,
|
|
419
|
+
"#{study_subject.subject_type}"
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
test "should not be case unless explicitly told" do
|
|
423
|
+
study_subject = create_study_subject
|
|
424
|
+
assert !study_subject.is_case?
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
test "should case if explicitly told" do
|
|
428
|
+
study_subject = Factory(:case_study_subject)
|
|
429
|
+
assert study_subject.is_case?
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
test "should return concat of 3 fields as to_s" do
|
|
433
|
+
study_subject = create_study_subject
|
|
434
|
+
# [childid,'(',studyid,full_name,')'].compact.join(' ')
|
|
435
|
+
assert_equal "#{study_subject}",
|
|
436
|
+
[study_subject.childid,'(',study_subject.studyid,study_subject.full_name,')'].compact.join(' ')
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
test "should create_home_exposure_with_study_subject" do
|
|
440
|
+
study_subject = create_home_exposure_with_study_subject
|
|
441
|
+
assert study_subject.is_a?(StudySubject)
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
test "should create_home_exposure_with_study_subject with patient" do
|
|
445
|
+
study_subject = create_home_exposure_with_study_subject(:patient => true)
|
|
446
|
+
assert study_subject.is_a?(StudySubject)
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
test "should return nil for next_control_orderno for control" do
|
|
450
|
+
study_subject = create_complete_control_study_subject
|
|
451
|
+
assert study_subject.is_control?
|
|
452
|
+
assert_equal nil, study_subject.next_control_orderno
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
test "should return nil for next_control_orderno for mother" do
|
|
456
|
+
study_subject = create_complete_mother_study_subject
|
|
457
|
+
assert study_subject.is_mother?
|
|
458
|
+
assert_equal nil, study_subject.next_control_orderno
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
test "should return 1 for next_control_orderno for case with no controls" do
|
|
462
|
+
case_study_subject = create_case_study_subject
|
|
463
|
+
assert_equal 1, case_study_subject.next_control_orderno
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
test "should return 2 for next_control_orderno for case with one control" do
|
|
467
|
+
case_study_subject = create_case_study_subject
|
|
468
|
+
assert_equal 1, case_study_subject.next_control_orderno
|
|
469
|
+
control = create_control_study_subject(
|
|
470
|
+
:matchingid => case_study_subject.subjectid,
|
|
471
|
+
:case_control_type => '6', # <- default used for next_control_orderno
|
|
472
|
+
:orderno => case_study_subject.next_control_orderno )
|
|
473
|
+
assert_equal 2, case_study_subject.next_control_orderno
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
test "should create mother when isn't one" do
|
|
477
|
+
study_subject = create_complete_control_study_subject
|
|
478
|
+
assert_nil study_subject.mother
|
|
479
|
+
assert_difference('StudySubject.count',1) {
|
|
480
|
+
@mother = study_subject.create_mother
|
|
481
|
+
}
|
|
482
|
+
assert_equal @mother, study_subject.mother
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
test "should copy mothers names when create mother for case" do
|
|
486
|
+
study_subject = create_complete_case_study_subject(
|
|
487
|
+
:mother_first_name => 'First',
|
|
488
|
+
:mother_middle_name => 'Middle',
|
|
489
|
+
:mother_last_name => 'Last',
|
|
490
|
+
:mother_maiden_name => 'Maiden')
|
|
491
|
+
assert_nil study_subject.reload.mother
|
|
492
|
+
assert_difference('StudySubject.count',1) {
|
|
493
|
+
@mother = study_subject.create_mother
|
|
494
|
+
assert_equal @mother.first_name, 'First'
|
|
495
|
+
assert_equal @mother.middle_name, 'Middle'
|
|
496
|
+
assert_equal @mother.last_name, 'Last'
|
|
497
|
+
assert_equal @mother.maiden_name, 'Maiden'
|
|
498
|
+
assert_equal @mother.first_name, study_subject.mother_first_name
|
|
499
|
+
assert_equal @mother.middle_name, study_subject.mother_middle_name
|
|
500
|
+
assert_equal @mother.last_name, study_subject.mother_last_name
|
|
501
|
+
assert_equal @mother.maiden_name, study_subject.mother_maiden_name
|
|
502
|
+
}
|
|
503
|
+
assert_equal @mother, study_subject.mother
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
test "should copy mothers names when create mother for control" do
|
|
507
|
+
study_subject = create_complete_control_study_subject(
|
|
508
|
+
:mother_first_name => 'First',
|
|
509
|
+
:mother_middle_name => 'Middle',
|
|
510
|
+
:mother_last_name => 'Last',
|
|
511
|
+
:mother_maiden_name => 'Maiden')
|
|
512
|
+
assert_nil study_subject.reload.mother
|
|
513
|
+
assert_difference('StudySubject.count',1) {
|
|
514
|
+
@mother = study_subject.create_mother
|
|
515
|
+
assert_equal @mother.first_name, 'First'
|
|
516
|
+
assert_equal @mother.middle_name, 'Middle'
|
|
517
|
+
assert_equal @mother.last_name, 'Last'
|
|
518
|
+
assert_equal @mother.maiden_name, 'Maiden'
|
|
519
|
+
assert_equal @mother.first_name, study_subject.mother_first_name
|
|
520
|
+
assert_equal @mother.middle_name, study_subject.mother_middle_name
|
|
521
|
+
assert_equal @mother.last_name, study_subject.mother_last_name
|
|
522
|
+
assert_equal @mother.maiden_name, study_subject.mother_maiden_name
|
|
523
|
+
}
|
|
524
|
+
assert_equal @mother, study_subject.mother
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
test "should copy mother_hispanicity_id when create mother for case" do
|
|
528
|
+
study_subject = create_complete_case_study_subject(
|
|
529
|
+
:mother_hispanicity_id => 123)
|
|
530
|
+
assert_equal study_subject.mother_hispanicity_id, 123
|
|
531
|
+
assert_nil study_subject.reload.mother
|
|
532
|
+
assert_difference('StudySubject.count',1) {
|
|
533
|
+
@mother = study_subject.create_mother
|
|
534
|
+
assert_equal @mother.hispanicity_id, 123
|
|
535
|
+
}
|
|
536
|
+
assert_equal @mother, study_subject.mother
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
test "should copy mother_hispanicity_id when create mother for control" do
|
|
540
|
+
study_subject = create_complete_control_study_subject(
|
|
541
|
+
:mother_hispanicity_id => 123)
|
|
542
|
+
assert_equal study_subject.mother_hispanicity_id, 123
|
|
543
|
+
assert_nil study_subject.reload.mother
|
|
544
|
+
assert_difference('StudySubject.count',1) {
|
|
545
|
+
@mother = study_subject.create_mother
|
|
546
|
+
assert_equal @mother.hispanicity_id, 123
|
|
547
|
+
}
|
|
548
|
+
assert_equal @mother, study_subject.mother
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
test "should not create mother when one exists" do
|
|
552
|
+
study_subject = create_complete_control_study_subject
|
|
553
|
+
mother = study_subject.create_mother
|
|
554
|
+
assert_difference('StudySubject.count',0) {
|
|
555
|
+
@mother = study_subject.create_mother
|
|
556
|
+
}
|
|
557
|
+
assert_equal @mother, mother
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
test "should not create mother for mother" do
|
|
561
|
+
study_subject = Factory(:complete_mother_study_subject)
|
|
562
|
+
assert_nil study_subject.familyid
|
|
563
|
+
assert_nil study_subject.mother
|
|
564
|
+
assert_equal study_subject, study_subject.create_mother
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
# test "should not create mother for subject without identifier" do
|
|
568
|
+
# study_subject = Factory(:study_subject)
|
|
569
|
+
# assert_nil study_subject.identifier
|
|
570
|
+
## TODO raise an error?
|
|
571
|
+
## mother = study_subject.create_mother
|
|
572
|
+
##flunk
|
|
573
|
+
# end
|
|
574
|
+
|
|
575
|
+
test "should get control subjects for case subject" do
|
|
576
|
+
study_subject = create_complete_case_study_subject
|
|
577
|
+
assert_equal [], study_subject.controls # aren't any controls, yet
|
|
578
|
+
control = create_control_study_subject(
|
|
579
|
+
:patid => study_subject.patid).reload
|
|
580
|
+
assert_equal [control], study_subject.controls
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
test "should get other control subjects for control subject" do
|
|
584
|
+
study_subject = create_complete_control_study_subject
|
|
585
|
+
assert_equal [], study_subject.controls
|
|
586
|
+
control = create_control_study_subject
|
|
587
|
+
# both have nil patid so not particularly helpful 'patid = NULL' doesn't work
|
|
588
|
+
assert_equal [], study_subject.controls
|
|
589
|
+
end
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
#
|
|
593
|
+
# matching/matchingid is for matching cases and controls
|
|
594
|
+
# This will also include case's family
|
|
595
|
+
#
|
|
596
|
+
test "should NOT include self in matching for case" do
|
|
597
|
+
study_subject = create_complete_case_study_subject
|
|
598
|
+
assert study_subject.is_case?
|
|
599
|
+
assert_equal 0, study_subject.matching.length
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
test "should NOT include self in matching for control" do
|
|
603
|
+
study_subject = create_complete_control_study_subject
|
|
604
|
+
assert study_subject.is_control?
|
|
605
|
+
assert_equal 0, study_subject.matching.length
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
test "should include mother in matching for case" do
|
|
609
|
+
study_subject = create_complete_case_study_subject
|
|
610
|
+
assert study_subject.is_case?
|
|
611
|
+
assert_not_nil study_subject.matchingid
|
|
612
|
+
mother = study_subject.create_mother
|
|
613
|
+
assert_equal study_subject.matching.length, 1
|
|
614
|
+
assert study_subject.matching.include?(mother)
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
test "should NOT include mother in matching for control" do
|
|
618
|
+
study_subject = create_complete_control_study_subject
|
|
619
|
+
assert study_subject.is_control?
|
|
620
|
+
assert_nil study_subject.matchingid
|
|
621
|
+
mother = study_subject.create_mother
|
|
622
|
+
assert_equal 0, study_subject.matching.length
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
test "should return nothing for null matchingid for matching" do
|
|
626
|
+
# only case is auto-assigned a matchingid
|
|
627
|
+
study_subject = Factory(:study_subject)
|
|
628
|
+
assert_nil study_subject.matchingid
|
|
629
|
+
assert_equal study_subject.matching.length, 0
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
#
|
|
634
|
+
# family/familyid is for matching subject to family members
|
|
635
|
+
#
|
|
636
|
+
test "should NOT include self in family for case" do
|
|
637
|
+
study_subject = create_complete_case_study_subject
|
|
638
|
+
assert study_subject.is_case?
|
|
639
|
+
assert_equal 0, study_subject.family.length
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
test "should NOT include self in family for control" do
|
|
643
|
+
study_subject = create_complete_control_study_subject
|
|
644
|
+
assert study_subject.is_control?
|
|
645
|
+
assert_equal 0, study_subject.family.length
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
test "should include mother in family for case" do
|
|
649
|
+
study_subject = create_complete_case_study_subject
|
|
650
|
+
assert study_subject.is_case?
|
|
651
|
+
mother = study_subject.create_mother
|
|
652
|
+
assert_equal study_subject.family.length, 1
|
|
653
|
+
assert study_subject.family.include?(mother)
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
test "should include mother in family for control" do
|
|
657
|
+
study_subject = create_complete_control_study_subject
|
|
658
|
+
assert study_subject.is_control?
|
|
659
|
+
mother = study_subject.create_mother
|
|
660
|
+
assert_equal study_subject.family.length, 1
|
|
661
|
+
assert study_subject.family.include?(mother)
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
test "should return nothing for null familyid for family" do
|
|
665
|
+
# only a mother won't be assigned a familyid
|
|
666
|
+
study_subject = Factory(:mother_study_subject)
|
|
667
|
+
assert_nil study_subject.familyid
|
|
668
|
+
assert_equal study_subject.family.length, 0
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
test "should return nil for mother with nil familyid" do
|
|
673
|
+
# only a mother won't be assigned a familyid
|
|
674
|
+
study_subject = Factory(:mother_study_subject)
|
|
675
|
+
assert_nil study_subject.familyid
|
|
676
|
+
assert_nil study_subject.mother
|
|
677
|
+
end
|
|
678
|
+
|
|
679
|
+
test "should return mother if is one" do
|
|
680
|
+
# TODO maybe return nil instead of self?
|
|
681
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
682
|
+
assert_nil study_subject.mother
|
|
683
|
+
mother = study_subject.create_mother
|
|
684
|
+
assert_not_nil study_subject.mother
|
|
685
|
+
assert_equal mother, study_subject.mother
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
test "should return rejected controls for case subject" do
|
|
690
|
+
study_subject = Factory(:complete_case_study_subject)
|
|
691
|
+
assert study_subject.is_case?
|
|
692
|
+
assert study_subject.rejected_controls.empty?
|
|
693
|
+
candidate_control = create_rejected_candidate_control(
|
|
694
|
+
:related_patid => study_subject.patid)
|
|
695
|
+
assert_equal [candidate_control], study_subject.rejected_controls
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
test "should return rejected controls for control subject" do
|
|
699
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
700
|
+
assert !study_subject.is_case?
|
|
701
|
+
assert study_subject.is_control?
|
|
702
|
+
assert study_subject.rejected_controls.empty?
|
|
703
|
+
candidate_control = create_rejected_candidate_control(
|
|
704
|
+
:related_patid => study_subject.patid)
|
|
705
|
+
assert_equal [], study_subject.rejected_controls
|
|
706
|
+
end
|
|
707
|
+
|
|
708
|
+
test "should return case by patid" do
|
|
709
|
+
Factory(:case_study_subject) # just another for noise
|
|
710
|
+
study_subject = Factory(:case_study_subject)
|
|
711
|
+
found_study_subject = StudySubject.find_case_by_patid(study_subject.patid)
|
|
712
|
+
assert_not_nil found_study_subject
|
|
713
|
+
assert_equal study_subject, found_study_subject
|
|
714
|
+
end
|
|
715
|
+
|
|
716
|
+
test "should return nothing if no case matching patid" do
|
|
717
|
+
study_subject = Factory(:case_study_subject)
|
|
718
|
+
found_study_subject = StudySubject.find_case_by_patid('0000')
|
|
719
|
+
assert_nil found_study_subject
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
test "should return child if subject is mother of case" do
|
|
723
|
+
study_subject = Factory(:complete_case_study_subject)
|
|
724
|
+
mother = study_subject.create_mother
|
|
725
|
+
assert_equal mother, study_subject.mother
|
|
726
|
+
assert_equal mother.child, study_subject
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
test "should return child if subject is mother of control" do
|
|
730
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
731
|
+
mother = study_subject.create_mother
|
|
732
|
+
assert_equal mother, study_subject.mother
|
|
733
|
+
assert_equal mother.child, study_subject
|
|
734
|
+
end
|
|
735
|
+
|
|
736
|
+
test "should return nil for child if is not mother" do
|
|
737
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
738
|
+
assert_nil study_subject.child
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
test "should return appended child's childid if is mother" do
|
|
742
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
743
|
+
mother = study_subject.create_mother
|
|
744
|
+
assert_not_nil study_subject.childid
|
|
745
|
+
assert_nil mother.childid
|
|
746
|
+
assert_not_nil mother.childid_to_s
|
|
747
|
+
assert_equal "#{study_subject.childid} (mother)", mother.childid_to_s
|
|
748
|
+
end
|
|
749
|
+
|
|
750
|
+
#
|
|
751
|
+
# As control is created attached to a case, it would be passed
|
|
752
|
+
# a patid and computed orderno. Creating an identifier on its
|
|
753
|
+
# own would create a partial studyid like '-1-' or something
|
|
754
|
+
# as the only thing the factory would create would be a random
|
|
755
|
+
# case control type. It should never actually be nil.
|
|
756
|
+
#
|
|
757
|
+
# test "should return nil for subjects without studyid" do
|
|
758
|
+
# study_subject = create_identifier(
|
|
759
|
+
# :patid => '0123', :orderno => 7 ).study_subject.reload
|
|
760
|
+
# assert_nil study_subject.studyid
|
|
761
|
+
# end
|
|
762
|
+
|
|
763
|
+
test "should return n/a for mother's studyid" do
|
|
764
|
+
study_subject = Factory(:complete_control_study_subject)
|
|
765
|
+
mother = study_subject.create_mother
|
|
766
|
+
assert_nil mother.studyid
|
|
767
|
+
assert_equal 'n/a', mother.studyid_to_s
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
end
|