pvdgm_services 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/Rakefile +40 -0
  4. data/app/contexts/services/accept_hl7_message_context.rb +32 -0
  5. data/app/contexts/services/application_mds_context.rb +21 -0
  6. data/app/contexts/services/complete_sltc_registration_process_context.rb +23 -0
  7. data/app/contexts/services/create_account_mapping_context.rb +23 -0
  8. data/app/contexts/services/create_configured_account_context.rb +26 -0
  9. data/app/contexts/services/create_configured_facility_context.rb +26 -0
  10. data/app/contexts/services/create_credential_context.rb +23 -0
  11. data/app/contexts/services/create_facility_mapping_context.rb +23 -0
  12. data/app/contexts/services/create_public_key_context.rb +22 -0
  13. data/app/contexts/services/create_service_context.rb +22 -0
  14. data/app/contexts/services/create_service_definition_context.rb +26 -0
  15. data/app/contexts/services/create_sltc_registration_context.rb +24 -0
  16. data/app/contexts/services/create_third_party_context.rb +22 -0
  17. data/app/contexts/services/hl7_message_trimming_context.rb +19 -0
  18. data/app/contexts/services/invoke_service_context.rb +21 -0
  19. data/app/contexts/services/list_sltc_providers_context.rb +22 -0
  20. data/app/contexts/services/mds_file_processing_context.rb +27 -0
  21. data/app/contexts/services/mds_file_upload_context.rb +25 -0
  22. data/app/contexts/services/mds_pull_context.rb +21 -0
  23. data/app/contexts/services/monthly_service_table_cleanup_context.rb +19 -0
  24. data/app/contexts/services/notify_new_registration_context.rb +22 -0
  25. data/app/contexts/services/notify_sltc_provider_change_context.rb +19 -0
  26. data/app/contexts/services/request_sltc_baseline_context.rb +23 -0
  27. data/app/contexts/services/update_account_mapping_context.rb +23 -0
  28. data/app/contexts/services/update_configured_account_context.rb +26 -0
  29. data/app/contexts/services/update_configured_facility_context.rb +26 -0
  30. data/app/contexts/services/update_credential_context.rb +23 -0
  31. data/app/contexts/services/update_facility_mapping_context.rb +23 -0
  32. data/app/contexts/services/update_public_key_context.rb +23 -0
  33. data/app/contexts/services/update_service_context.rb +23 -0
  34. data/app/contexts/services/update_service_definition_context.rb +26 -0
  35. data/app/contexts/services/update_third_party_context.rb +23 -0
  36. data/app/controllers/services/account_mappings_controller.rb +54 -0
  37. data/app/controllers/services/adts_controller.rb +35 -0
  38. data/app/controllers/services/application_controller.rb +17 -0
  39. data/app/controllers/services/assessment_requests_controller.rb +48 -0
  40. data/app/controllers/services/available_files_controller.rb +19 -0
  41. data/app/controllers/services/configured_account_base_controller.rb +17 -0
  42. data/app/controllers/services/configured_accounts_controller.rb +59 -0
  43. data/app/controllers/services/configured_facilities_controller.rb +65 -0
  44. data/app/controllers/services/facility_mappings_controller.rb +58 -0
  45. data/app/controllers/services/mds_files_controller.rb +75 -0
  46. data/app/controllers/services/mds_pull_accounts_controller.rb +57 -0
  47. data/app/controllers/services/public_keys_controller.rb +50 -0
  48. data/app/controllers/services/service_base_controller.rb +18 -0
  49. data/app/controllers/services/service_definition_base_controller.rb +31 -0
  50. data/app/controllers/services/service_definitions_controller.rb +59 -0
  51. data/app/controllers/services/services_controller.rb +56 -0
  52. data/app/controllers/services/sltc_providers_controller.rb +15 -0
  53. data/app/controllers/services/sltc_registrations_controller.rb +74 -0
  54. data/app/controllers/services/status_masking.rb +17 -0
  55. data/app/controllers/services/third_parties_controller.rb +47 -0
  56. data/app/controllers/services/third_party_base_controller.rb +17 -0
  57. data/app/controllers/services/validation_controller.rb +17 -0
  58. data/app/helpers/services/application_helper.rb +8 -0
  59. data/app/helpers/services/assessment_request_helper.rb +19 -0
  60. data/app/helpers/services/available_files_helper.rb +27 -0
  61. data/app/helpers/services/mds_pull_accounts_helper.rb +27 -0
  62. data/app/helpers/services/sltc_registrations_helper.rb +15 -0
  63. data/app/mailers/services_mailer.rb +57 -0
  64. data/app/models/services/abaqis_mds_push.rb +51 -0
  65. data/app/models/services/account_mapping.rb +10 -0
  66. data/app/models/services/application_api.rb +19 -0
  67. data/app/models/services/assessment_request.rb +18 -0
  68. data/app/models/services/available_file.rb +73 -0
  69. data/app/models/services/configured_account.rb +26 -0
  70. data/app/models/services/configured_facility.rb +16 -0
  71. data/app/models/services/credential.rb +9 -0
  72. data/app/models/services/facility_mapping.rb +12 -0
  73. data/app/models/services/ftp_server.rb +69 -0
  74. data/app/models/services/hl7_inbound_service.rb +47 -0
  75. data/app/models/services/hl7_message.rb +27 -0
  76. data/app/models/services/isc_code.rb +15 -0
  77. data/app/models/services/isc_code_lookup.rb +75 -0
  78. data/app/models/services/mds_assessment.rb +371 -0
  79. data/app/models/services/mds_content.rb +55 -0
  80. data/app/models/services/mds_pull.rb +41 -0
  81. data/app/models/services/mds_pull_account.rb +192 -0
  82. data/app/models/services/mds_push.rb +24 -0
  83. data/app/models/services/mds_upload.rb +64 -0
  84. data/app/models/services/mds_upload_content.rb +148 -0
  85. data/app/models/services/mds_ws_response.rb +21 -0
  86. data/app/models/services/mds_ws_response_handler.rb +31 -0
  87. data/app/models/services/pcc_mds_pull.rb +77 -0
  88. data/app/models/services/provider_change.rb +26 -0
  89. data/app/models/services/public_key.rb +11 -0
  90. data/app/models/services/service.rb +20 -0
  91. data/app/models/services/service_definition.rb +37 -0
  92. data/app/models/services/service_implementation.rb +29 -0
  93. data/app/models/services/sltc_api.rb +179 -0
  94. data/app/models/services/sltc_api_exception.rb +54 -0
  95. data/app/models/services/sltc_mds_pull.rb +230 -0
  96. data/app/models/services/sltc_registration.rb +23 -0
  97. data/app/models/services/third_party.rb +18 -0
  98. data/app/roles/services/account_mapping_creator.rb +13 -0
  99. data/app/roles/services/account_mapping_updator.rb +12 -0
  100. data/app/roles/services/configured_account_creator.rb +13 -0
  101. data/app/roles/services/configured_account_updater.rb +12 -0
  102. data/app/roles/services/configured_facility_creator.rb +13 -0
  103. data/app/roles/services/configured_facility_updater.rb +12 -0
  104. data/app/roles/services/credential_creator.rb +11 -0
  105. data/app/roles/services/credential_updater.rb +20 -0
  106. data/app/roles/services/facility_mapping_creator.rb +13 -0
  107. data/app/roles/services/facility_mapping_updater.rb +11 -0
  108. data/app/roles/services/hl7_adt_message_saver.rb +15 -0
  109. data/app/roles/services/hl7_message_trimmer.rb +14 -0
  110. data/app/roles/services/mds_assessment_categorizer.rb +71 -0
  111. data/app/roles/services/mds_file_processor.rb +86 -0
  112. data/app/roles/services/mds_notifications.rb +44 -0
  113. data/app/roles/services/monthly_service_table_cleaner.rb +19 -0
  114. data/app/roles/services/new_registration_notifier.rb +11 -0
  115. data/app/roles/services/public_key_creator.rb +14 -0
  116. data/app/roles/services/public_key_updater.rb +12 -0
  117. data/app/roles/services/service_creator.rb +13 -0
  118. data/app/roles/services/service_definition_creator.rb +13 -0
  119. data/app/roles/services/service_definition_updater.rb +12 -0
  120. data/app/roles/services/service_invoker.rb +25 -0
  121. data/app/roles/services/service_updater.rb +11 -0
  122. data/app/roles/services/sltc_baseline_requestor.rb +19 -0
  123. data/app/roles/services/sltc_provider_change_notifier.rb +25 -0
  124. data/app/roles/services/sltc_provider_lister.rb +13 -0
  125. data/app/roles/services/sltc_registration_completer.rb +81 -0
  126. data/app/roles/services/sltc_registration_saver.rb +13 -0
  127. data/app/roles/services/submit_mds_file_for_processing.rb +28 -0
  128. data/app/roles/services/third_party_creator.rb +13 -0
  129. data/app/roles/services/third_party_updater.rb +12 -0
  130. data/app/utils/services/file_upload_handler.rb +33 -0
  131. data/app/utils/services/mds_upload_filters.rb +26 -0
  132. data/app/utils/services/mds_xml_file_parser.rb +104 -0
  133. data/app/utils/services/upload_file.rb +13 -0
  134. data/app/validators/isc_code_validator.rb +42 -0
  135. data/app/validators/mds_birthdate_validator.rb +37 -0
  136. data/app/validators/mds_date_validator.rb +8 -0
  137. data/app/validators/mds_integer_validator.rb +15 -0
  138. data/app/validators/mds_version_validator.rb +16 -0
  139. data/app/validators/state_code_validator.rb +9 -0
  140. data/app/views/layouts/services/application.html.erb +14 -0
  141. data/app/views/services/account_mappings/index.json.jbuilder +9 -0
  142. data/app/views/services/account_mappings/show.json.jbuilder +7 -0
  143. data/app/views/services/assessment_requests/index.json.jbuilder +11 -0
  144. data/app/views/services/available_files/index.json.jbuilder +13 -0
  145. data/app/views/services/configured_accounts/index.json.jbuilder +13 -0
  146. data/app/views/services/configured_accounts/show.json.jbuilder +11 -0
  147. data/app/views/services/configured_facilities/index.json.jbuilder +13 -0
  148. data/app/views/services/configured_facilities/show.json.jbuilder +11 -0
  149. data/app/views/services/facility_mappings/index.json.jbuilder +10 -0
  150. data/app/views/services/facility_mappings/show.json.jbuilder +8 -0
  151. data/app/views/services/mds_files/create.builder +10 -0
  152. data/app/views/services/mds_pull_accounts/index.json.jbuilder +11 -0
  153. data/app/views/services/public_keys/index.json.jbuilder +8 -0
  154. data/app/views/services/public_keys/show.json.jbuilder +6 -0
  155. data/app/views/services/service_definitions/index.json.jbuilder +17 -0
  156. data/app/views/services/service_definitions/show.json.jbuilder +16 -0
  157. data/app/views/services/services/index.json.jbuilder +6 -0
  158. data/app/views/services/services/show.json.jbuilder +4 -0
  159. data/app/views/services/sltc_providers/index.json.jbuilder +10 -0
  160. data/app/views/services/sltc_registrations/index.json.jbuilder +10 -0
  161. data/app/views/services/third_parties/index.json.jbuilder +7 -0
  162. data/app/views/services/third_parties/show.json.jbuilder +5 -0
  163. data/app/views/services_mailer/burying_job.html.erb +20 -0
  164. data/app/views/services_mailer/delaying_job.html.erb +20 -0
  165. data/app/views/services_mailer/notify_sltc_client_registration.html.erb +39 -0
  166. data/app/views/services_mailer/notify_sltc_client_registration_invalid_request_type.html.erb +8 -0
  167. data/app/views/services_mailer/notify_sltc_client_registration_request_invalid.html.erb +10 -0
  168. data/app/views/services_mailer/notify_sltc_client_registration_validation_errors.html.erb +13 -0
  169. data/app/views/services_mailer/notify_sltc_provider_changes.html.erb +26 -0
  170. data/app/views/services_mailer/notify_support_about_no_mds_pull.html.erb +6 -0
  171. data/config/routes.rb +48 -0
  172. data/db/migrate/20140102000000_create_services_engine_tables.rb +131 -0
  173. data/db/migrate/20140517184450_new_services_columns.rb +24 -0
  174. data/db/migrate/20140525142842_new_configured_provider_table.rb +18 -0
  175. data/db/migrate/20140714172442_add_error_column_to_hl7_messages.rb +5 -0
  176. data/db/migrate/20140730164152_mds_upload_tables.rb +78 -0
  177. data/db/sql_data/service_data_setup.sql +24 -0
  178. data/lib/services/engine.rb +40 -0
  179. data/lib/services/version.rb +3 -0
  180. data/lib/services.rb +4 -0
  181. data/lib/tasks/services_tasks.rake +40 -0
  182. data/spec/dummy/README.rdoc +261 -0
  183. data/spec/dummy/Rakefile +7 -0
  184. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  185. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  186. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  187. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  188. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  189. data/spec/dummy/config/application.rb +60 -0
  190. data/spec/dummy/config/boot.rb +10 -0
  191. data/spec/dummy/config/database.yml +29 -0
  192. data/spec/dummy/config/environment.rb +5 -0
  193. data/spec/dummy/config/environments/development.rb +35 -0
  194. data/spec/dummy/config/environments/production.rb +68 -0
  195. data/spec/dummy/config/environments/test.rb +32 -0
  196. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  197. data/spec/dummy/config/initializers/email.rb +1 -0
  198. data/spec/dummy/config/initializers/inflections.rb +15 -0
  199. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  200. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  201. data/spec/dummy/config/initializers/session_store.rb +8 -0
  202. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  203. data/spec/dummy/config/locales/en.yml +5 -0
  204. data/spec/dummy/config/routes.rb +4 -0
  205. data/spec/dummy/config.ru +4 -0
  206. data/spec/dummy/db/schema.rb +237 -0
  207. data/spec/dummy/db/sql_data/services_isc_codes.sql +878 -0
  208. data/spec/dummy/log/test.log +3498 -0
  209. data/spec/dummy/public/404.html +26 -0
  210. data/spec/dummy/public/422.html +26 -0
  211. data/spec/dummy/public/500.html +25 -0
  212. data/spec/dummy/public/favicon.ico +0 -0
  213. data/spec/dummy/script/rails +6 -0
  214. data/spec/models/abaqis_mds_push_spec.rb +120 -0
  215. data/spec/models/available_file_spec.rb +234 -0
  216. data/spec/models/configured_account_spec.rb +39 -0
  217. data/spec/models/ftp_server_spec.rb +221 -0
  218. data/spec/models/isc_code_lookup_spec.rb +125 -0
  219. data/spec/models/isc_code_spec.rb +5 -0
  220. data/spec/models/mds_assessment_spec.rb +1070 -0
  221. data/spec/models/mds_pull_account_spec.rb +468 -0
  222. data/spec/models/mds_pull_spec.rb +48 -0
  223. data/spec/models/mds_push_spec.rb +43 -0
  224. data/spec/models/mds_ws_response_spec.rb +54 -0
  225. data/spec/models/pcc_mds_pull_spec.rb +273 -0
  226. data/spec/models/service_implementation_spec.rb +88 -0
  227. data/spec/models/sltc_api_exception_spec.rb +136 -0
  228. data/spec/models/sltc_api_spec.rb +192 -0
  229. data/spec/models/sltc_mds_pull_spec.rb +776 -0
  230. data/spec/roles/account_mapping_creator_spec.rb +40 -0
  231. data/spec/roles/account_mapping_updator_spec.rb +16 -0
  232. data/spec/roles/configured_account_creator_spec.rb +40 -0
  233. data/spec/roles/configured_account_updater_spec.rb +16 -0
  234. data/spec/roles/configured_facility_creator_spec.rb +40 -0
  235. data/spec/roles/configured_facility_updater_spec.rb +16 -0
  236. data/spec/roles/credential_creator_spec.rb +23 -0
  237. data/spec/roles/credential_updater_spec.rb +38 -0
  238. data/spec/roles/facility_mapping_creator_spec.rb +40 -0
  239. data/spec/roles/facility_mapping_updater_spec.rb +16 -0
  240. data/spec/roles/hl7_adt_message_saver_spec.rb +35 -0
  241. data/spec/roles/hl7_message_trimmer_spec.rb +31 -0
  242. data/spec/roles/monthly_service_table_cleaner_spec.rb +27 -0
  243. data/spec/roles/new_registration_notifier_spec.rb +18 -0
  244. data/spec/roles/service_ceator_spec.rb +34 -0
  245. data/spec/roles/service_definition_creator_spec.rb +40 -0
  246. data/spec/roles/service_definition_updater_spec.rb +16 -0
  247. data/spec/roles/service_invoker_spec.rb +22 -0
  248. data/spec/roles/service_updater_spec.rb +17 -0
  249. data/spec/roles/sltc_baseline_requestor_spec.rb +30 -0
  250. data/spec/roles/sltc_provider_lister_spec.rb +27 -0
  251. data/spec/roles/sltc_registration_completer_spec.rb +187 -0
  252. data/spec/roles/sltc_registration_saver_spec.rb +34 -0
  253. data/spec/roles/third_party_creator_spec.rb +34 -0
  254. data/spec/roles/third_party_updater_spec.rb +17 -0
  255. data/spec/spec_helper.rb +72 -0
  256. metadata +581 -0
@@ -0,0 +1,1070 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::MdsAssessment do
4
+ let(:mds) { Services::MdsAssessment.new }
5
+
6
+ context 'Validation' do
7
+
8
+ context 'Responses' do
9
+ it "reports only 1 error if no responses are provided" do
10
+ expect(mds).to_not be_valid
11
+ expect(mds).to have(1).errors
12
+ expect(mds).to have(1).errors_on(:responses)
13
+ end
14
+ end
15
+
16
+ context 'Fac ID' do
17
+
18
+ it "reports when missing" do
19
+ mds.responses = { 'itm_sbst_cd' => '09' }
20
+
21
+ expect(mds).to_not be_valid
22
+ expect(mds).to have(1).errors_on(:fac_id)
23
+ end
24
+
25
+ it "reports when present, but empty" do
26
+ mds.responses = { 'itm_sbst_cd' => '09', 'fac_id' => '' }
27
+
28
+ expect(mds).to_not be_valid
29
+ expect(mds).to have(1).errors_on(:fac_id)
30
+ end
31
+
32
+ it "reports no error when present" do
33
+ mds.responses = { 'itm_sbst_cd' => '09', 'fac_id' => '23401' }
34
+
35
+ expect(mds).to_not be_valid
36
+ expect(mds).to have(0).errors_on(:fac_id)
37
+ end
38
+
39
+ end
40
+
41
+ context 'Item Subset Code' do
42
+
43
+ #it "raises argument exception when not present" do
44
+ #mds.responses = { 'a0100b' => 'abc123' }
45
+
46
+ #expect{mds.valid?}.to raise_error(ArgumentError)
47
+ #end
48
+
49
+ it "reports error when value is empty" do
50
+ mds.responses = { 'itm_sbst_cd' => '' }
51
+
52
+ expect(mds).to_not be_valid
53
+ expect(mds).to have(2).errors_on(:itm_sbst_cd)
54
+ end
55
+
56
+ it "reports error when value is invalid" do
57
+ mds.responses = { 'itm_sbst_cd' => 'BOB' }
58
+
59
+ expect(mds).to_not be_valid
60
+ expect(mds).to have(1).errors_on(:itm_sbst_cd)
61
+ end
62
+
63
+ it "reports no error when value is valid" do
64
+ mds.responses = { 'itm_sbst_cd' => 'NT' }
65
+
66
+ expect(mds).to_not be_valid
67
+ expect(mds).to have(1).errors_on(:itm_sbst_cd)
68
+ end
69
+
70
+ end
71
+
72
+ context 'State Code' do
73
+
74
+ it "reports an error when no state code is provided" do
75
+ mds.responses = { 'itm_sbst_cd' => 'NT' }
76
+
77
+ expect(mds).to_not be_valid
78
+ expect(mds).to have(1).errors_on(:state_cd)
79
+ end
80
+
81
+ it "reports an error when state code is invalid" do
82
+ mds.responses = { 'itm_sbst_cd' => 'NT', 'state_cd' => 'BZ' }
83
+
84
+ expect(mds).to_not be_valid
85
+ expect(mds).to have(1).errors_on(:state_cd)
86
+ end
87
+
88
+ it "reports no error when state code is valid" do
89
+ mds.responses = { 'itm_sbst_cd' => 'NT', 'state_cd' => 'VT' }
90
+
91
+ expect(mds).to_not be_valid
92
+ expect(mds).to have(0).errors_on(:state_cd)
93
+ end
94
+
95
+ end
96
+
97
+ context 'a1600' do
98
+
99
+ it "reports no error if missing but not an inactivation assessment" do
100
+ mds.version = Services::MdsAssessment::VERSION1_1
101
+ mds.responses = { 'itm_sbst_cd' => 'XX', 'a0050' => '3', 'x0600f' => '10', 'x0700b' => '20140803' } # Inactivation code
102
+
103
+ expect(mds).to_not be_valid
104
+ expect(mds).to have(0).errors_on(:itm_sbst_cd)
105
+ expect(mds).to have(0).errors_on(:a1600)
106
+ end
107
+
108
+ it "reports no error if the date is specified" do
109
+ mds.version = Services::MdsAssessment::VERSION1_1
110
+ mds.responses = { 'itm_sbst_cd' => 'NT', 'a0050' => '1', 'a1600' => '20140101', 'a0200' => '1', 'a0310a' => '99', 'a0310b' => '99', 'a0310c' => '0', 'a0310d' => '^', 'a0310f' => '01' }
111
+
112
+ expect(mds).to_not be_valid
113
+ expect(mds).to have(0).errors_on(:itm_sbst_cd)
114
+ expect(mds).to have(0).errors_on(:a1600)
115
+ end
116
+
117
+ it "reports an error if an invalid date is specified" do
118
+ mds.version = Services::MdsAssessment::VERSION1_1
119
+ mds.responses = { 'itm_sbst_cd' => 'NT', 'a0050' => '1', 'a1600' => '20142191', 'a0200' => '1', 'a0310a' => '99', 'a0310b' => '99', 'a0310c' => '0', 'a0310d' => '^', 'a0310f' => '01' }
120
+
121
+ expect(mds).to_not be_valid
122
+ expect(mds).to have(0).errors_on(:itm_sbst_cd)
123
+ expect(mds).to have(1).errors_on(:a1600)
124
+ end
125
+
126
+ end
127
+
128
+ context 'a2000' do
129
+
130
+ it "reports an error if missing and discharge assessment" do
131
+ mds.responses = { 'a0310f' => '11' }
132
+
133
+ expect(mds).to_not be_valid
134
+ expect(mds).to have(1).errors_on(:a2000);
135
+ end
136
+
137
+ it "reports an error if missing and death assessment" do
138
+ mds.responses = { 'a0310f' => '12' }
139
+
140
+ expect(mds).to_not be_valid
141
+ expect(mds).to have(1).errors_on(:a2000);
142
+ end
143
+
144
+ it "reports no error if missing for non-discharge" do
145
+ mds.responses = { 'a0310f' => '8' }
146
+
147
+ expect(mds).to_not be_valid
148
+ expect(mds).to have(0).errors_on(:a2000);
149
+ end
150
+
151
+ it "reports no error if present for discharge" do
152
+ mds.responses = { 'a0310f' => '11', 'a2000' => '20140101' }
153
+
154
+ expect(mds).to_not be_valid
155
+ expect(mds).to have(0).errors_on(:a2000);
156
+ end
157
+
158
+ it "reports an error if present but invalid for discharge" do
159
+ mds.responses = { 'a0310f' => '10', 'a2000' => '20149191' }
160
+
161
+ expect(mds).to_not be_valid
162
+ expect(mds).to have(1).errors_on(:a2000);
163
+ end
164
+
165
+ end
166
+
167
+ context 'a2300' do
168
+
169
+ it "reports no error if missing and a0310f is not 99" do
170
+ mds.responses = { 'a0310f' => '88' }
171
+
172
+ expect(mds).to_not be_valid
173
+ expect(mds).to have(0).errors_on(:a2300)
174
+ end
175
+
176
+ it "reports an error if missing and a0310f is 99" do
177
+ mds.responses = { 'a0310f' => '99' }
178
+
179
+ expect(mds).to_not be_valid
180
+ expect(mds).to have(1).errors_on(:a2300)
181
+ end
182
+
183
+ it "reports an error if invalid and a0310f is 99" do
184
+ mds.responses = { 'a0310f' => '99', 'a2300' => '20149191' }
185
+
186
+ expect(mds).to_not be_valid
187
+ expect(mds).to have(1).errors_on(:a2300)
188
+ end
189
+
190
+ it "reports no error if valid and a0310f is 99" do
191
+ mds.responses = { 'a0310f' => '99', 'a2300' => '20140101' }
192
+
193
+ expect(mds).to_not be_valid
194
+ expect(mds).to have(0).errors_on(:a2300)
195
+ end
196
+
197
+ end
198
+
199
+ context 'a0900' do
200
+
201
+ it "reports no error when not specified" do
202
+ mds.responses = { 'a0310f' => '88' }
203
+
204
+ expect(mds).to_not be_valid
205
+ expect(mds).to have(0).errors_on(:a0900)
206
+ end
207
+
208
+ it "reports no error when just the year is specified" do
209
+ mds.responses = { 'a0310f' => '88', 'a0900' => '2014' }
210
+
211
+ expect(mds).to_not be_valid
212
+ expect(mds).to have(0).errors_on(:a0900)
213
+ end
214
+
215
+ it "reports no error when just the year and month is specified" do
216
+ mds.responses = { 'a0310f' => '88', 'a0900' => '201407' }
217
+
218
+ expect(mds).to_not be_valid
219
+ expect(mds).to have(0).errors_on(:a0900)
220
+ end
221
+
222
+ it "reports no error when just the year, month and day is specified" do
223
+ mds.responses = { 'a0310f' => '88', 'a0900' => '20140704' }
224
+
225
+ expect(mds).to_not be_valid
226
+ expect(mds).to have(0).errors_on(:a0900)
227
+ end
228
+
229
+ it "reports an error when an invalid date is specified" do
230
+ mds.responses = { 'a0310f' => '88', 'a0900' => '20149794' }
231
+
232
+ expect(mds).to_not be_valid
233
+ expect(mds).to have(1).errors_on(:a0900)
234
+ end
235
+
236
+ it "reports an error when an invalid date with non-numerics is specified" do
237
+ mds.responses = { 'a0310f' => '88', 'a0900' => '20a49794' }
238
+
239
+ expect(mds).to_not be_valid
240
+ expect(mds).to have(1).errors_on(:a0900)
241
+ end
242
+
243
+ end
244
+
245
+ context 'k0200a' do
246
+
247
+ it "reports no error if not specified" do
248
+ mds.responses = { 'a0310f' => '8' }
249
+
250
+ expect(mds).to_not be_valid
251
+ expect(mds).to have(0).errors_on(:k0200a)
252
+ end
253
+
254
+ it "reports no error if valid" do
255
+ mds.responses = { 'k0200a' => '9' }
256
+
257
+ expect(mds).to_not be_valid
258
+ expect(mds).to have(0).errors_on(:k0200a)
259
+ end
260
+
261
+ it "reports an error if invalid" do
262
+ mds.responses = { 'k0200a' => '901' }
263
+
264
+ expect(mds).to_not be_valid
265
+ expect(mds).to have(1).errors_on(:k0200a)
266
+ end
267
+
268
+ it "reports no error if one of the bizarre mds characters" do
269
+ mds.responses = { 'k0200a' => '^' }
270
+
271
+ expect(mds).to_not be_valid
272
+ expect(mds).to have(0).errors_on(:k0200a)
273
+ end
274
+
275
+ end
276
+
277
+ context 'k0200b' do
278
+
279
+ it "reports no error if not specified" do
280
+ mds.responses = { 'a0310f' => '8' }
281
+
282
+ expect(mds).to_not be_valid
283
+ expect(mds).to have(0).errors_on(:k0200b)
284
+ end
285
+
286
+ it "reports no error if valid" do
287
+ mds.responses = { 'k0200b' => '9' }
288
+
289
+ expect(mds).to_not be_valid
290
+ expect(mds).to have(0).errors_on(:k0200b)
291
+ end
292
+
293
+ it "reports an error if invalid" do
294
+ mds.responses = { 'k0200b' => '9010' }
295
+
296
+ expect(mds).to_not be_valid
297
+ expect(mds).to have(1).errors_on(:k0200b)
298
+ end
299
+
300
+ it "reports no error if one of the bizarre mds characters" do
301
+ mds.responses = { 'k0200b' => '^' }
302
+
303
+ expect(mds).to_not be_valid
304
+ expect(mds).to have(0).errors_on(:k0200b)
305
+ end
306
+
307
+ end
308
+
309
+ context 'version' do
310
+
311
+ it "reports an error if no version is specified" do
312
+ mds.responses = { 'a0310f' => '4' }
313
+
314
+ expect(mds).to_not be_valid
315
+ expect(mds).to have(1).errors_on(:version)
316
+ end
317
+
318
+ it "reports no error if version 1.10 is specified and a0050 is specified" do
319
+ mds.version = Services::MdsAssessment::VERSION1_1
320
+ mds.responses = { 'a0050' => '1' }
321
+
322
+ expect(mds).to_not be_valid
323
+ expect(mds).to have(0).errors_on(:version)
324
+ end
325
+
326
+ it "reports no error if version 1.00 is specified and x0100 is specified" do
327
+ mds.version = Services::MdsAssessment::VERSION1_0
328
+ mds.responses = { 'x0100' => '1' }
329
+
330
+ expect(mds).to_not be_valid
331
+ expect(mds).to have(0).errors_on(:version)
332
+ end
333
+
334
+ it "reports an error if an invalid version is specified and x0100 is specified" do
335
+ mds.version = "3.2"
336
+ mds.responses = { 'x0100' => '1' }
337
+
338
+ expect(mds).to_not be_valid
339
+ expect(mds).to have(1).errors_on(:version)
340
+ end
341
+
342
+ it "reports an error if version 1.10 is specified and a0050 is not specified" do
343
+ mds.version = Services::MdsAssessment::VERSION1_1
344
+ mds.responses = { 'a0100b' => '1' }
345
+
346
+ expect(mds).to_not be_valid
347
+ expect(mds).to have(1).errors_on(:version)
348
+ end
349
+
350
+ it "reports an error if version 1.00 is specified and x0100 is not specified" do
351
+ mds.version = Services::MdsAssessment::VERSION1_0
352
+ mds.responses = { 'a0100b' => '1' }
353
+
354
+ expect(mds).to_not be_valid
355
+ expect(mds).to have(1).errors_on(:version)
356
+ end
357
+
358
+ end
359
+
360
+ context 'twisted discharge dates' do
361
+
362
+ it 'reports no error if this is not a discharge or death assessment' do
363
+ mds.responses = { 'a0310f' => '8', 'a1600' => '20140102', 'a2000' => '20140101' }
364
+
365
+ expect(mds).to_not be_valid
366
+ expect(mds).to have(0).errors_on('entry_discharge_dates')
367
+ end
368
+
369
+ it 'reports no error if this is a discharge assessment with no twisted dates' do
370
+ mds.responses = { 'a0310f' => '10', 'a1600' => '20140102', 'a2000' => '20140103' }
371
+
372
+ expect(mds).to_not be_valid
373
+ expect(mds).to have(0).errors_on('entry_discharge_dates')
374
+ end
375
+
376
+ it 'reports no error if this is a death assessment with no twisted dates' do
377
+ mds.responses = { 'a0310f' => '12', 'a1600' => '20140102', 'a2000' => '20140103' }
378
+
379
+ expect(mds).to_not be_valid
380
+ expect(mds).to have(0).errors_on('entry_discharge_dates')
381
+ end
382
+
383
+ it 'reports an error if this is a discharge assessment with twisted dates' do
384
+ mds.responses = { 'a0310f' => '10', 'a1600' => '20140102', 'a2000' => '20140101' }
385
+
386
+ expect(mds).to_not be_valid
387
+ expect(mds).to have(1).errors_on('entry_discharge_dates')
388
+ end
389
+
390
+ it 'reports an error if this is a death assessment with twisted dates' do
391
+ mds.responses = { 'a0310f' => '12', 'a1600' => '20140102', 'a2000' => '20140101' }
392
+
393
+ expect(mds).to_not be_valid
394
+ expect(mds).to have(1).errors_on('entry_discharge_dates')
395
+ end
396
+
397
+
398
+ end
399
+
400
+ context 'reference date' do
401
+
402
+ it "will be the value of a1600 if this is an entry assessment" do
403
+ mds.responses = { 'a0310f' => '1', 'a1600' => '20140803' }
404
+
405
+ expect(mds).to_not be_valid
406
+ expect(mds.reference_date.strftime("%Y%m%d")).to eq('20140803')
407
+ end
408
+
409
+ it "will be the value of a2000 if this is a death assessment" do
410
+ mds.responses = { 'a0310f' => '12', 'a2000' => '20140803' }
411
+
412
+ expect(mds).to_not be_valid
413
+ expect(mds.reference_date.strftime("%Y%m%d")).to eq('20140803')
414
+ end
415
+
416
+ it "will be the value of x0700b if this is an inactivation assessment" do
417
+ mds.responses = { 'itm_sbst_cd' => 'XX', 'x0600f' => '10', 'x0700b' => '20140803' }
418
+
419
+ expect(mds).to_not be_valid
420
+ expect(mds.reference_date.strftime("%Y%m%d")).to eq('20140803')
421
+ end
422
+
423
+ end
424
+
425
+ context 'version' do
426
+
427
+ it "will be '1.00' if the reference date is before April 1, 2012" do
428
+ mds.responses = { 'a0310f' => '1', 'a1600' => '20120203' }
429
+
430
+ expect(mds).to_not be_valid
431
+ expect(mds.version).to eq('1.00')
432
+ end
433
+
434
+ it "will be '1.10' if the reference date is after April 1, 2012" do
435
+ mds.responses = { 'a0310f' => '1', 'a1600' => '20120703' }
436
+
437
+ expect(mds).to_not be_valid
438
+ expect(mds.version).to eq('1.10')
439
+ end
440
+
441
+ end
442
+
443
+ end
444
+
445
+ context 'inact_corr_match_fields' do
446
+
447
+ it 'returns the list of fields for 99' do
448
+ expect(mds.send(:inact_corr_match_fields, 99)).to eq(%w{ x0150 x0600a x0600b x0600c x0600d x0600f x0700a })
449
+ end
450
+
451
+ it 'returns the list of fields for 01' do
452
+ expect(mds.send(:inact_corr_match_fields, 01)).to eq(%w{ x0150 x0600a x0600b x0600c x0600d x0600f x0700c })
453
+ end
454
+
455
+ it 'returns the list of fields for 10' do
456
+ expect(mds.send(:inact_corr_match_fields, 10)).to eq(%w{ x0150 x0600a x0600b x0600c x0600d x0600f x0700b })
457
+ end
458
+
459
+ it 'returns the list of fields for 11' do
460
+ expect(mds.send(:inact_corr_match_fields, 11)).to eq(%w{ x0150 x0600a x0600b x0600c x0600d x0600f x0700b })
461
+ end
462
+
463
+ it 'returns the list of fields for 12' do
464
+ expect(mds.send(:inact_corr_match_fields, 12)).to eq(%w{ x0150 x0600a x0600b x0600c x0600d x0600f x0700b })
465
+ end
466
+
467
+ end
468
+
469
+ context 'hash_field_values' do
470
+
471
+ it 'returns hash for target fields' do
472
+ mds.responses = { 'x0150' => 'v1', 'a0100b' => 'snits', 'x0600a' => '31' }
473
+
474
+ expect(mds.send(:hash_field_values, %w{ x0150 x0600a x0600b })).to eq(Digest::MD5.hexdigest("x0150=v1,x0600a=31,x0600b="))
475
+ end
476
+
477
+ it 'returns hash for the non-target fields' do
478
+ mds.responses = { 'a0200' => 'v1', 'a0100b' => 'snits', 'a0310a' => '31' }
479
+ expect(mds.send(:hash_field_values, %w{ x0150 x0600a x0600b }, false)).to eq(Digest::MD5.hexdigest("x0150=v1,x0600a=31,x0600b="))
480
+ end
481
+
482
+ end
483
+
484
+ context 'admission matching' do
485
+ let (:admission) {
486
+ Services::MdsAssessment.create!( responses: {
487
+ 'x0100' => '1', 'a0050' => '1',
488
+ 'fac_id' => 'whisp',
489
+ 'state_cd' => 'CO',
490
+ 'a1600' => '20140817',
491
+ 'a2000' => '^',
492
+ 'itm_sbst_cd' => 'NC',
493
+ 'a0200' => '1',
494
+ 'a0310a' => '01',
495
+ 'a0310b' => '99',
496
+ 'a0310c' => '0',
497
+ 'a0310d' => '^',
498
+ 'a0310f' => '99',
499
+ 'a2300' => '20140826'
500
+ }) }
501
+
502
+ it "finds a correction record for an admission" do
503
+ correction = Services::MdsAssessment.create!( responses: {
504
+ 'x0100' => '2', 'a0050' => '2',
505
+ 'a2200' => '20140827',
506
+ 'fac_id' => 'whisp',
507
+ 'state_cd' => 'CO',
508
+ 'a1600' => '20140817',
509
+ 'a2000' => '^',
510
+ 'a2300' => '20140827',
511
+ 'itm_sbst_cd' => 'NC',
512
+ 'a0200' => '1',
513
+ 'a0310a' => '05',
514
+ 'a0310b' => '99',
515
+ 'a0310c' => '0',
516
+ 'a0310d' => '^',
517
+ 'a0310f' => '99',
518
+ 'x0600f' => '99',
519
+ 'x0150' => '1',
520
+ 'x0600a' => '01',
521
+ 'x0600b' => '99',
522
+ 'x0600c' => '0',
523
+ 'x0600d' => '^',
524
+ 'x0700a' => '20140826'
525
+ })
526
+
527
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(admission).first
528
+
529
+ expect(matching_assessment).to be_present
530
+ expect(matching_assessment.id).to eq(correction.id)
531
+
532
+ end
533
+
534
+ it "finds an inactivation record for an admission" do
535
+ inactivation = Services::MdsAssessment.create!( responses: {
536
+ 'x0100' => '3', 'a0050' => '3',
537
+ 'fac_id' => 'whisp',
538
+ 'state_cd' => 'CO',
539
+ 'itm_sbst_cd' => 'XX',
540
+ 'x0600f' => '99',
541
+ 'x0150' => '1',
542
+ 'x0600a' => '01',
543
+ 'x0600b' => '99',
544
+ 'x0600c' => '0',
545
+ 'x0600d' => '^',
546
+ 'x0700a' => '20140826'
547
+ })
548
+
549
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(admission).first
550
+
551
+ expect(matching_assessment).to be_present
552
+ expect(matching_assessment.id).to eq(inactivation.id)
553
+
554
+ end
555
+
556
+ end
557
+
558
+ context 'annual matching' do
559
+ let (:annual) {
560
+ Services::MdsAssessment.create!( responses: {
561
+ 'x0100' => '1', 'a0050' => '1',
562
+ 'fac_id' => 'whisp',
563
+ 'state_cd' => 'CO',
564
+ 'a1600' => '20140817',
565
+ 'a2000' => '^',
566
+ 'itm_sbst_cd' => 'NC',
567
+ 'a0200' => '1',
568
+ 'a0310a' => '03',
569
+ 'a0310b' => '99',
570
+ 'a0310c' => '0',
571
+ 'a0310d' => '^',
572
+ 'a0310f' => '99',
573
+ 'a2300' => '20140828'
574
+ }) }
575
+
576
+ it "finds a correction record for an annual assessment" do
577
+ correction = Services::MdsAssessment.create!( responses: {
578
+ 'x0100' => '2', 'a0050' => '2',
579
+ 'a2200' => '20140827',
580
+ 'fac_id' => 'whisp',
581
+ 'state_cd' => 'CO',
582
+ 'a1600' => '20140817',
583
+ 'a2000' => '^',
584
+ 'a2300' => '20140827',
585
+ 'itm_sbst_cd' => 'NC',
586
+ 'a0200' => '1',
587
+ 'a0310a' => '05',
588
+ 'a0310b' => '99',
589
+ 'a0310c' => '0',
590
+ 'a0310d' => '^',
591
+ 'a0310f' => '99',
592
+ 'x0600f' => '99',
593
+ 'x0150' => '1',
594
+ 'x0600a' => '03',
595
+ 'x0600b' => '99',
596
+ 'x0600c' => '0',
597
+ 'x0600d' => '^',
598
+ 'x0700a' => '20140828'
599
+ })
600
+
601
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(annual).first
602
+
603
+ expect(matching_assessment).to be_present
604
+ expect(matching_assessment.id).to eq(correction.id)
605
+
606
+ end
607
+
608
+ it "finds an inactivation record for an annual assessment" do
609
+ inactivation = Services::MdsAssessment.create!( responses: {
610
+ 'x0100' => '3', 'a0050' => '3',
611
+ 'fac_id' => 'whisp',
612
+ 'state_cd' => 'CO',
613
+ 'itm_sbst_cd' => 'XX',
614
+ 'x0600f' => '99',
615
+ 'x0150' => '1',
616
+ 'x0600a' => '03',
617
+ 'x0600b' => '99',
618
+ 'x0600c' => '0',
619
+ 'x0600d' => '^',
620
+ 'x0700a' => '20140828'
621
+ })
622
+
623
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(annual).first
624
+
625
+ expect(matching_assessment).to be_present
626
+ expect(matching_assessment.id).to eq(inactivation.id)
627
+
628
+ end
629
+
630
+ end
631
+
632
+ context 'death matching' do
633
+ let (:death) {
634
+ Services::MdsAssessment.create!( responses: {
635
+ 'x0100' => '1', 'a0050' => '1',
636
+ 'fac_id' => 'whisp',
637
+ 'state_cd' => 'CO',
638
+ 'a1600' => '20140817',
639
+ 'a2000' => '20140902',
640
+ 'itm_sbst_cd' => 'NT',
641
+ 'a0200' => '1',
642
+ 'a0310a' => '99',
643
+ 'a0310b' => '99',
644
+ 'a0310c' => '0',
645
+ 'a0310d' => '^',
646
+ 'a0310f' => '12',
647
+ 'a2300' => '^'
648
+ }) }
649
+
650
+ it "finds a correction record for a death assessment" do
651
+ correction = Services::MdsAssessment.create!( responses: {
652
+ 'x0100' => '2', 'a0050' => '2',
653
+ 'fac_id' => 'whisp',
654
+ 'state_cd' => 'CO',
655
+ 'a1600' => '20140817',
656
+ 'a2000' => '20140902',
657
+ 'a2300' => '20140827',
658
+ 'itm_sbst_cd' => 'NT',
659
+ 'a0200' => '1',
660
+ 'a0310a' => '99',
661
+ 'a0310b' => '99',
662
+ 'a0310c' => '0',
663
+ 'a0310d' => '^',
664
+ 'a0310f' => '12',
665
+ 'x0600f' => '12',
666
+ 'x0150' => '1',
667
+ 'x0600a' => '99',
668
+ 'x0600b' => '99',
669
+ 'x0600c' => '0',
670
+ 'x0600d' => '^',
671
+ 'x0700b' => '20140902'
672
+ })
673
+
674
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(death).first
675
+
676
+ expect(matching_assessment).to be_present
677
+ expect(matching_assessment.id).to eq(correction.id)
678
+
679
+ end
680
+
681
+ it "finds an inactivation record for an death assessment" do
682
+ inactivation = Services::MdsAssessment.create!( responses: {
683
+ 'x0100' => '3', 'a0050' => '3',
684
+ 'fac_id' => 'whisp',
685
+ 'state_cd' => 'CO',
686
+ 'itm_sbst_cd' => 'XX',
687
+ 'x0600f' => '12',
688
+ 'x0150' => '1',
689
+ 'x0600a' => '99',
690
+ 'x0600b' => '99',
691
+ 'x0600c' => '0',
692
+ 'x0600d' => '^',
693
+ 'x0700b' => '20140902'
694
+ })
695
+
696
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(death).first
697
+
698
+ expect(matching_assessment).to be_present
699
+ expect(matching_assessment.id).to eq(inactivation.id)
700
+
701
+ end
702
+
703
+ end
704
+
705
+ context 'discharge ra matching' do
706
+ let (:discharge) {
707
+ Services::MdsAssessment.create!( responses: {
708
+ 'x0100' => '1', 'a0050' => '1',
709
+ 'fac_id' => 'whisp',
710
+ 'state_cd' => 'CO',
711
+ 'a1600' => '20140817',
712
+ 'a2000' => '20140902',
713
+ 'itm_sbst_cd' => 'ND',
714
+ 'a0200' => '1',
715
+ 'a0310a' => '99',
716
+ 'a0310b' => '99',
717
+ 'a0310c' => '0',
718
+ 'a0310d' => '^',
719
+ 'a0310f' => '11',
720
+ 'a2300' => '^'
721
+ }) }
722
+
723
+ it "finds a correction record for a discharge ra assessment" do
724
+ correction = Services::MdsAssessment.create!( responses: {
725
+ 'x0100' => '2', 'a0050' => '2',
726
+ 'fac_id' => 'whisp',
727
+ 'state_cd' => 'CO',
728
+ 'a1600' => '20140817',
729
+ 'a2000' => '20140902',
730
+ 'a2300' => '20140827',
731
+ 'itm_sbst_cd' => 'ND',
732
+ 'a0200' => '1',
733
+ 'a0310a' => '99',
734
+ 'a0310b' => '99',
735
+ 'a0310c' => '0',
736
+ 'a0310d' => '^',
737
+ 'a0310f' => '11',
738
+ 'x0600f' => '11',
739
+ 'x0150' => '1',
740
+ 'x0600a' => '99',
741
+ 'x0600b' => '99',
742
+ 'x0600c' => '0',
743
+ 'x0600d' => '^',
744
+ 'x0700b' => '20140902'
745
+ })
746
+
747
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(discharge).first
748
+
749
+ expect(matching_assessment).to be_present
750
+ expect(matching_assessment.id).to eq(correction.id)
751
+
752
+ end
753
+
754
+ it "finds an inactivation record for a discharge ra assessment" do
755
+ inactivation = Services::MdsAssessment.create!( responses: {
756
+ 'x0100' => '3', 'a0050' => '3',
757
+ 'fac_id' => 'whisp',
758
+ 'state_cd' => 'CO',
759
+ 'itm_sbst_cd' => 'XX',
760
+ 'x0600f' => '11',
761
+ 'x0150' => '1',
762
+ 'x0600a' => '99',
763
+ 'x0600b' => '99',
764
+ 'x0600c' => '0',
765
+ 'x0600d' => '^',
766
+ 'x0700b' => '20140902'
767
+ })
768
+
769
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(discharge).first
770
+
771
+ expect(matching_assessment).to be_present
772
+ expect(matching_assessment.id).to eq(inactivation.id)
773
+
774
+ end
775
+
776
+ end
777
+
778
+ context 'discharge rna matching' do
779
+ let (:discharge) {
780
+ Services::MdsAssessment.create!( responses: {
781
+ 'x0100' => '1', 'a0050' => '1',
782
+ 'fac_id' => 'whisp',
783
+ 'state_cd' => 'CO',
784
+ 'a1600' => '20140817',
785
+ 'a2000' => '20140902',
786
+ 'itm_sbst_cd' => 'ND',
787
+ 'a0200' => '1',
788
+ 'a0310a' => '99',
789
+ 'a0310b' => '99',
790
+ 'a0310c' => '0',
791
+ 'a0310d' => '^',
792
+ 'a0310f' => '10',
793
+ 'a2300' => '^'
794
+ }) }
795
+
796
+ it "finds a correction record for a discharge rna assessment" do
797
+ correction = Services::MdsAssessment.create!( responses: {
798
+ 'x0100' => '2', 'a0050' => '2',
799
+ 'fac_id' => 'whisp',
800
+ 'state_cd' => 'CO',
801
+ 'a1600' => '20140817',
802
+ 'a2000' => '20140902',
803
+ 'a2300' => '20140827',
804
+ 'itm_sbst_cd' => 'ND',
805
+ 'a0200' => '1',
806
+ 'a0310a' => '99',
807
+ 'a0310b' => '99',
808
+ 'a0310c' => '0',
809
+ 'a0310d' => '^',
810
+ 'a0310f' => '10',
811
+ 'x0600f' => '10',
812
+ 'x0150' => '1',
813
+ 'x0600a' => '99',
814
+ 'x0600b' => '99',
815
+ 'x0600c' => '0',
816
+ 'x0600d' => '^',
817
+ 'x0700b' => '20140902'
818
+ })
819
+
820
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(discharge).first
821
+
822
+ expect(matching_assessment).to be_present
823
+ expect(matching_assessment.id).to eq(correction.id)
824
+
825
+ end
826
+
827
+ it "finds an inactivation record for discharge rna assessment" do
828
+ inactivation = Services::MdsAssessment.create!( responses: {
829
+ 'x0100' => '3', 'a0050' => '3',
830
+ 'fac_id' => 'whisp',
831
+ 'state_cd' => 'CO',
832
+ 'itm_sbst_cd' => 'XX',
833
+ 'x0600f' => '10',
834
+ 'x0150' => '1',
835
+ 'x0600a' => '99',
836
+ 'x0600b' => '99',
837
+ 'x0600c' => '0',
838
+ 'x0600d' => '^',
839
+ 'x0700b' => '20140902'
840
+ })
841
+
842
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(discharge).first
843
+
844
+ expect(matching_assessment).to be_present
845
+ expect(matching_assessment.id).to eq(inactivation.id)
846
+
847
+ end
848
+
849
+ end
850
+
851
+ context 'entry matching' do
852
+ let (:entry) {
853
+ Services::MdsAssessment.create!( responses: {
854
+ 'x0100' => '1', 'a0050' => '1',
855
+ 'fac_id' => 'whisp',
856
+ 'state_cd' => 'CO',
857
+ 'a1600' => '20140817',
858
+ 'a2000' => '^',
859
+ 'itm_sbst_cd' => 'NT',
860
+ 'a0200' => '1',
861
+ 'a0310a' => '99',
862
+ 'a0310b' => '99',
863
+ 'a0310c' => '0',
864
+ 'a0310d' => '^',
865
+ 'a0310f' => '01',
866
+ 'a2300' => '^'
867
+ }) }
868
+
869
+ it "finds a correction record for an entry assessment" do
870
+ correction = Services::MdsAssessment.create!( responses: {
871
+ 'x0100' => '2', 'a0050' => '2',
872
+ 'fac_id' => 'whisp',
873
+ 'state_cd' => 'CO',
874
+ 'a1600' => '20140817',
875
+ 'a2000' => '^',
876
+ 'a2300' => '20140827',
877
+ 'itm_sbst_cd' => 'NT',
878
+ 'a0200' => '1',
879
+ 'a0310a' => '99',
880
+ 'a0310b' => '99',
881
+ 'a0310c' => '0',
882
+ 'a0310d' => '^',
883
+ 'a0310f' => '01',
884
+ 'x0600f' => '01',
885
+ 'x0150' => '1',
886
+ 'x0600a' => '99',
887
+ 'x0600b' => '99',
888
+ 'x0600c' => '0',
889
+ 'x0600d' => '^',
890
+ 'x0700c' => '20140817'
891
+ })
892
+
893
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(entry).first
894
+
895
+ expect(matching_assessment).to be_present
896
+ expect(matching_assessment.id).to eq(correction.id)
897
+
898
+ end
899
+
900
+ it "finds an inactivation record for an entry assessment" do
901
+ inactivation = Services::MdsAssessment.create!( responses: {
902
+ 'x0100' => '3', 'a0050' => '3',
903
+ 'fac_id' => 'whisp',
904
+ 'state_cd' => 'CO',
905
+ 'itm_sbst_cd' => 'XX',
906
+ 'x0600f' => '01',
907
+ 'x0150' => '1',
908
+ 'x0600a' => '99',
909
+ 'x0600b' => '99',
910
+ 'x0600c' => '0',
911
+ 'x0600d' => '^',
912
+ 'x0700c' => '20140817'
913
+ })
914
+
915
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(entry).first
916
+
917
+ expect(matching_assessment).to be_present
918
+ expect(matching_assessment.id).to eq(inactivation.id)
919
+
920
+ end
921
+
922
+ end
923
+
924
+ context 'quarterly matching' do
925
+ let (:quarterly) {
926
+ Services::MdsAssessment.create!( responses: {
927
+ 'x0100' => '1', 'a0050' => '1',
928
+ 'fac_id' => 'whisp',
929
+ 'state_cd' => 'CO',
930
+ 'a1600' => '20140817',
931
+ 'a2000' => '^',
932
+ 'itm_sbst_cd' => 'NQ',
933
+ 'a0200' => '1',
934
+ 'a0310a' => '02',
935
+ 'a0310b' => '99',
936
+ 'a0310c' => '0',
937
+ 'a0310d' => '^',
938
+ 'a0310f' => '99',
939
+ 'a2300' => '20140827'
940
+ }) }
941
+
942
+ it "finds a correction record for a quarterly assessment" do
943
+ correction = Services::MdsAssessment.create!( responses: {
944
+ 'x0100' => '2', 'a0050' => '2',
945
+ 'fac_id' => 'whisp',
946
+ 'state_cd' => 'CO',
947
+ 'a1600' => '20140817',
948
+ 'a2000' => '^',
949
+ 'a2300' => '20140827',
950
+ 'itm_sbst_cd' => 'NQ',
951
+ 'a0200' => '1',
952
+ 'a0310a' => '06',
953
+ 'a0310b' => '99',
954
+ 'a0310c' => '0',
955
+ 'a0310d' => '^',
956
+ 'a0310f' => '99',
957
+ 'x0600f' => '99',
958
+ 'x0150' => '1',
959
+ 'x0600a' => '02',
960
+ 'x0600b' => '99',
961
+ 'x0600c' => '0',
962
+ 'x0600d' => '^',
963
+ 'x0700a' => '20140827'
964
+ })
965
+
966
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(quarterly).first
967
+
968
+ expect(matching_assessment).to be_present
969
+ expect(matching_assessment.id).to eq(correction.id)
970
+
971
+ end
972
+
973
+ it "finds an inactivation record for a quarterly assessment" do
974
+ inactivation = Services::MdsAssessment.create!( responses: {
975
+ 'x0100' => '3', 'a0050' => '3',
976
+ 'fac_id' => 'whisp',
977
+ 'state_cd' => 'CO',
978
+ 'itm_sbst_cd' => 'XX',
979
+ 'x0600f' => '99',
980
+ 'x0150' => '1',
981
+ 'x0600a' => '02',
982
+ 'x0600b' => '99',
983
+ 'x0600c' => '0',
984
+ 'x0600d' => '^',
985
+ 'x0700a' => '20140827'
986
+ })
987
+
988
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(quarterly).first
989
+
990
+ expect(matching_assessment).to be_present
991
+ expect(matching_assessment.id).to eq(inactivation.id)
992
+
993
+ end
994
+
995
+ end
996
+
997
+ context 'significant change matching' do
998
+ let (:change) {
999
+ Services::MdsAssessment.create!( responses: {
1000
+ 'x0100' => '1', 'a0050' => '1',
1001
+ 'fac_id' => 'whisp',
1002
+ 'state_cd' => 'CO',
1003
+ 'a1600' => '20140817',
1004
+ 'a2000' => '^',
1005
+ 'itm_sbst_cd' => 'NC',
1006
+ 'a0200' => '1',
1007
+ 'a0310a' => '04',
1008
+ 'a0310b' => '99',
1009
+ 'a0310c' => '0',
1010
+ 'a0310d' => '^',
1011
+ 'a0310f' => '99',
1012
+ 'a2300' => '20140829'
1013
+ }) }
1014
+
1015
+ it "finds a correction record for a significant change assessment" do
1016
+ correction = Services::MdsAssessment.create!( responses: {
1017
+ 'x0100' => '2', 'a0050' => '2',
1018
+ 'fac_id' => 'whisp',
1019
+ 'state_cd' => 'CO',
1020
+ 'a1600' => '20140817',
1021
+ 'a2000' => '^',
1022
+ 'a2300' => '20140827',
1023
+ 'itm_sbst_cd' => 'NC',
1024
+ 'a0200' => '1',
1025
+ 'a0310a' => '04',
1026
+ 'a0310b' => '99',
1027
+ 'a0310c' => '0',
1028
+ 'a0310d' => '^',
1029
+ 'a0310f' => '99',
1030
+ 'x0600f' => '99',
1031
+ 'x0150' => '1',
1032
+ 'x0600a' => '04',
1033
+ 'x0600b' => '99',
1034
+ 'x0600c' => '0',
1035
+ 'x0600d' => '^',
1036
+ 'x0700a' => '20140829'
1037
+ })
1038
+
1039
+ matching_assessment = Services::MdsAssessment.correction_assessments_for_target(change).first
1040
+
1041
+ expect(matching_assessment).to be_present
1042
+ expect(matching_assessment.id).to eq(correction.id)
1043
+
1044
+ end
1045
+
1046
+ it "finds an inactivation record for a significant change assessment" do
1047
+ inactivation = Services::MdsAssessment.create!( responses: {
1048
+ 'x0100' => '3', 'a0050' => '3',
1049
+ 'fac_id' => 'whisp',
1050
+ 'state_cd' => 'CO',
1051
+ 'itm_sbst_cd' => 'XX',
1052
+ 'x0600f' => '99',
1053
+ 'x0150' => '1',
1054
+ 'x0600a' => '04',
1055
+ 'x0600b' => '99',
1056
+ 'x0600c' => '0',
1057
+ 'x0600d' => '^',
1058
+ 'x0700a' => '20140829'
1059
+ })
1060
+
1061
+ matching_assessment = Services::MdsAssessment.inactivation_assessments_for_target(change).first
1062
+
1063
+ expect(matching_assessment).to be_present
1064
+ expect(matching_assessment.id).to eq(inactivation.id)
1065
+
1066
+ end
1067
+
1068
+ end
1069
+
1070
+ end