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,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::AccountMappingCreator do
4
+ let(:third_party) { Services::ThirdParty.new.tap { | tp | tp.extend Services::AccountMappingCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the account mapping and save it if is valid" do
9
+ params = {}
10
+
11
+ m_am = mock_model(Services::AccountMapping)
12
+ m_am.should_receive(:valid?).and_return(true)
13
+ m_am.should_receive(:save)
14
+
15
+ m_am_rel = double("AccountMappingRelationship")
16
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
17
+
18
+ third_party.should_receive(:account_mappings).and_return(m_am_rel)
19
+
20
+ expect(third_party.create(params)).to be(m_am)
21
+ end
22
+
23
+ it "should create the account mapping but not save it if is invalid" do
24
+ params = {}
25
+
26
+ m_am = mock_model(Services::AccountMapping)
27
+ m_am.should_receive(:valid?).and_return(false)
28
+ m_am.should_not_receive(:save)
29
+
30
+ m_am_rel = double("AccountMappingRelationship")
31
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
32
+
33
+ third_party.should_receive(:account_mappings).and_return(m_am_rel)
34
+
35
+ expect(third_party.create(params)).to be(m_am)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::AccountMappingUpdator do
4
+ let(:account_mapping) { Services::AccountMapping.new.tap { | am | am.extend Services::AccountMappingUpdator } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the AccountMapping object with the specified parameters" do
9
+ params = {}
10
+ account_mapping.should_receive(:update_attributes).with(params).and_return(account_mapping)
11
+ expect(account_mapping.update(params)).to be(account_mapping)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ConfiguredAccountCreator do
4
+ let(:service_definition) { Services::ThirdParty.new.tap { | tp | tp.extend Services::ConfiguredAccountCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the account mapping and save it if is valid" do
9
+ params = {}
10
+
11
+ m_am = mock_model(Services::ConfiguredAccount)
12
+ m_am.should_receive(:valid?).and_return(true)
13
+ m_am.should_receive(:save)
14
+
15
+ m_am_rel = double("ConfiguredAccountRelationship")
16
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
17
+
18
+ service_definition.should_receive(:configured_accounts).and_return(m_am_rel)
19
+
20
+ expect(service_definition.create(params)).to be(m_am)
21
+ end
22
+
23
+ it "should create the account mapping but not save it if is invalid" do
24
+ params = {}
25
+
26
+ m_am = mock_model(Services::ConfiguredAccount)
27
+ m_am.should_receive(:valid?).and_return(false)
28
+ m_am.should_not_receive(:save)
29
+
30
+ m_am_rel = double("ConfiguredAccountRelationship")
31
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
32
+
33
+ service_definition.should_receive(:configured_accounts).and_return(m_am_rel)
34
+
35
+ expect(service_definition.create(params)).to be(m_am)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ConfiguredAccountUpdater do
4
+ let(:configured_account) { Services::ConfiguredAccount.new.tap { | am | am.extend Services::ConfiguredAccountUpdater } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the ConfiguredAccount object with the specified parameters" do
9
+ params = {}
10
+ configured_account.should_receive(:update_attributes).with(params).and_return(configured_account)
11
+ expect(configured_account.update(params)).to be(configured_account)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ConfiguredFacilityCreator do
4
+ let(:service_definition) { Services::ThirdParty.new.tap { | tp | tp.extend Services::ConfiguredFacilityCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the account mapping and save it if is valid" do
9
+ params = {}
10
+
11
+ m_am = mock_model(Services::ConfiguredFacility)
12
+ m_am.should_receive(:valid?).and_return(true)
13
+ m_am.should_receive(:save)
14
+
15
+ m_am_rel = double("ConfiguredFacilityRelationship")
16
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
17
+
18
+ service_definition.should_receive(:configured_facilities).and_return(m_am_rel)
19
+
20
+ expect(service_definition.create(params)).to be(m_am)
21
+ end
22
+
23
+ it "should create the account mapping but not save it if is invalid" do
24
+ params = {}
25
+
26
+ m_am = mock_model(Services::ConfiguredFacility)
27
+ m_am.should_receive(:valid?).and_return(false)
28
+ m_am.should_not_receive(:save)
29
+
30
+ m_am_rel = double("ConfiguredFacilityRelationship")
31
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
32
+
33
+ service_definition.should_receive(:configured_facilities).and_return(m_am_rel)
34
+
35
+ expect(service_definition.create(params)).to be(m_am)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ConfiguredFacilityUpdater do
4
+ let(:configured_facility) { Services::ConfiguredFacility.new.tap { | am | am.extend Services::ConfiguredFacilityUpdater } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the ConfiguredFacility object with the specified parameters" do
9
+ params = {}
10
+ configured_facility.should_receive(:update_attributes).with(params).and_return(configured_facility)
11
+ expect(configured_facility.update(params)).to be(configured_facility)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::CredentialCreator do
4
+ let(:configured_account) { Services::ConfiguredAccount.new.tap { | cred | cred.extend Services::CredentialCreator } }
5
+
6
+ context '#add_credential' do
7
+
8
+ it "should append a new credential set to credential" do
9
+ params = { token: 'abc123' }
10
+
11
+ m_cred = mock_model(Services::Credential)
12
+
13
+ Services::Credential.should_receive(:new).with(params).and_return(m_cred)
14
+
15
+ m_creds = double("Credentials")
16
+ m_creds.should_receive(:<<).with(m_cred)
17
+ configured_account.should_receive(:credentials).and_return(m_creds)
18
+
19
+ configured_account.add_credential(params)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::CredentialUpdater do
4
+ let(:configured_account) { Services::ConfiguredAccount.new.tap { | ca | ca.extend Services::CredentialUpdater } }
5
+
6
+ context '#update_credential' do
7
+
8
+ it "should update existing credential if one already exists" do
9
+ params = { password: 'abc123' }
10
+
11
+ m_cred = mock_model(Services::Credential)
12
+ m_cred.should_receive(:update_attributes).with(params)
13
+
14
+ configured_account.should_receive(:credentials).and_return([ m_cred ])
15
+
16
+ configured_account.update_credential(params)
17
+ end
18
+
19
+ it "should create a new set of credentials if they don't already exist" do
20
+ params = { password: 'abc123' }
21
+
22
+ m_cred = mock_model(Services::Credential)
23
+ # m_cred.should_receive(:update_attributes).with(params)
24
+
25
+ Services::Credential.should_receive(:new).with(params).and_return(m_cred)
26
+
27
+ m_creds = double("Credentials")
28
+ m_creds.should_receive(:first).and_return(nil)
29
+ m_creds.should_receive(:<<).with(m_cred)
30
+
31
+ configured_account.should_receive(:credentials).exactly(2).times.and_return(m_creds)
32
+
33
+ configured_account.update_credential(params)
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::FacilityMappingCreator do
4
+ let(:third_party) { Services::ThirdParty.new.tap { | tp | tp.extend Services::FacilityMappingCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the facility mapping and save it if is valid" do
9
+ params = {}
10
+
11
+ m_am = mock_model(Services::FacilityMapping)
12
+ m_am.should_receive(:valid?).and_return(true)
13
+ m_am.should_receive(:save)
14
+
15
+ m_am_rel = double("FacilityMappingRelationship")
16
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
17
+
18
+ third_party.should_receive(:facility_mappings).and_return(m_am_rel)
19
+
20
+ expect(third_party.create(params)).to be(m_am)
21
+ end
22
+
23
+ it "should create the facility mapping but not save it if is invalid" do
24
+ params = {}
25
+
26
+ m_am = mock_model(Services::FacilityMapping)
27
+ m_am.should_receive(:valid?).and_return(false)
28
+ m_am.should_not_receive(:save)
29
+
30
+ m_am_rel = double("FacilityMappingRelationship")
31
+ m_am_rel.should_receive(:new).with(params).and_return(m_am)
32
+
33
+ third_party.should_receive(:facility_mappings).and_return(m_am_rel)
34
+
35
+ expect(third_party.create(params)).to be(m_am)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::FacilityMappingUpdater do
4
+ let(:facility_mapping) { Services::FacilityMapping.new.tap { | am | am.extend Services::FacilityMappingUpdater } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the FacilityMapping object with the specified parameters" do
9
+ params = {}
10
+ facility_mapping.should_receive(:update_attributes).with(params).and_return(facility_mapping)
11
+ expect(facility_mapping.update(params)).to be(facility_mapping)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::Hl7AdtMessageSaver do
4
+ let(:context) { Object.new.tap { |context| context.extend Services::Hl7AdtMessageSaver } }
5
+
6
+ context '#persist' do
7
+
8
+ it "should save the message if it is valid" do
9
+ m_msg = mock_model(Services::Hl7Message)
10
+ m_msg.should_receive(:message_type=).with('A01')
11
+ m_msg.should_receive(:message=).with('message body')
12
+ m_msg.should_receive(:valid?).and_return(true)
13
+ m_msg.should_receive(:save)
14
+
15
+ Services::Hl7Message.should_receive(:new).and_return(m_msg)
16
+
17
+ expect(context.persist('A01', 'message body')).to be(m_msg)
18
+ end
19
+
20
+ it "should not save the message if it is valid" do
21
+ m_msg = mock_model(Services::Hl7Message)
22
+ m_msg.should_receive(:message_type=).with(nil)
23
+ m_msg.should_receive(:message=).with('message body')
24
+ m_msg.should_receive(:valid?).and_return(false)
25
+ m_msg.should_not_receive(:save)
26
+
27
+ Services::Hl7Message.should_receive(:new).and_return(m_msg)
28
+
29
+ expect(context.persist(nil, 'message body')).to be(m_msg)
30
+ end
31
+
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::Hl7MessageTrimmer do
4
+
5
+ it "will not delete HL7 Messages that are newer than 30 days regardless of status" do
6
+ # Create HL7 messages with each status and verify they don't get deleted
7
+ Services::Hl7Message.create(status: Services::Hl7Message::STATUS_RECEIVED, message_type: 'A08')
8
+ Services::Hl7Message.create(status: Services::Hl7Message::STATUS_PROCESSED, message_type: 'A08')
9
+ Services::Hl7Message.create(status: Services::Hl7Message::STATUS_ERRORED, message_type: 'A08')
10
+
11
+ Services::Hl7MessageTrimmingContext.call
12
+
13
+ expect(Services::Hl7Message.count).to be(3)
14
+ end
15
+
16
+ it "will delete all processed HL7 messages older than 30 days" do
17
+ m1 = Services::Hl7Message.create(status: Services::Hl7Message::STATUS_RECEIVED, message_type: 'A08')
18
+ m2 = Services::Hl7Message.create(status: Services::Hl7Message::STATUS_PROCESSED, message_type: 'A08')
19
+ m3 = Services::Hl7Message.create(status: Services::Hl7Message::STATUS_ERRORED, message_type: 'A08')
20
+
21
+ m1.update_attribute(:updated_at, Time.now - 31.days)
22
+ m2.update_attribute(:updated_at, Time.now - 31.days)
23
+ m3.update_attribute(:updated_at, Time.now - 31.days)
24
+
25
+ Services::Hl7MessageTrimmingContext.call
26
+
27
+ expect(Services::Hl7Message.count).to be(2)
28
+ expect(Services::Hl7Message.where(id: m2.id).count).to be(0)
29
+ end
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::MonthlyServiceTableCleaner do
4
+ let(:context) { Object.new.tap { | context | context.extend Services::MonthlyServiceTableCleaner } }
5
+
6
+ context '#where_clause' do
7
+
8
+ it "should_return a where clause with a status filter set" do
9
+ expect(context.send(:where_clause, 3)).to eq("DATEDIFF(CURRENT_DATE, created_at) > 30 AND status = 3")
10
+ end
11
+
12
+ end
13
+
14
+ context '#clean_up_service_tables' do
15
+
16
+ it "should clean up the assessment_requests, available_files and mds_pull_accounts tables" do
17
+ Services::AssessmentRequest.should_receive(:destroy_all).with("DATEDIFF(CURRENT_DATE, created_at) > 30 AND status = #{Services::AssessmentRequest::STATUS_COMPLETED}")
18
+ Services::AvailableFile.should_receive(:destroy_all).with("DATEDIFF(CURRENT_DATE, created_at) > 30 AND status = #{Services::AvailableFile::STATUS_CLEARED}")
19
+ Services::MdsPullAccount.should_receive(:destroy_all).with("DATEDIFF(CURRENT_DATE, created_at) > 30 AND status = #{Services::MdsPullAccount::STATUS_REMOTE_CLEAN}")
20
+
21
+ context.clean_up_service_tables
22
+ end
23
+
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::NewRegistrationNotifier do
4
+ let(:registration) { Services::SltcRegistration.new.tap { | reg | reg.extend Services::NewRegistrationNotifier } }
5
+
6
+ context '#notify' do
7
+
8
+ it "should send an email out" do
9
+ m_notification = double("MailerNotification")
10
+ m_notification.should_receive(:deliver)
11
+
12
+ ServicesMailer.should_receive(:notify_sltc_client_registration).with(registration).and_return(m_notification)
13
+
14
+ registration.notify
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ServiceCreator do
4
+ let(:context) { Object.new.tap { | tp | tp.extend Services::ServiceCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the service and save it if is valid" do
9
+ params = {}
10
+
11
+ m_svc = mock_model(Services::Service)
12
+ m_svc.should_receive(:valid?).and_return(true)
13
+ m_svc.should_receive(:save)
14
+
15
+ Services::Service.should_receive(:new).with(params).and_return(m_svc)
16
+
17
+ expect(context.create(params)).to be(m_svc)
18
+ end
19
+
20
+ it "should create the service but not save it if is invalid" do
21
+ params = {}
22
+
23
+ m_svc = mock_model(Services::Service)
24
+ m_svc.should_receive(:valid?).and_return(false)
25
+ m_svc.should_not_receive(:save)
26
+
27
+ Services::Service.should_receive(:new).with(params).and_return(m_svc)
28
+
29
+ expect(context.create(params)).to be(m_svc)
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ServiceDefinitionCreator do
4
+ let(:third_party) { Services::ThirdParty.new.tap { | tp | tp.extend Services::ServiceDefinitionCreator } }
5
+
6
+ context '#create' do
7
+
8
+ it "should create the service definition and save it if is valid" do
9
+ params = {}
10
+
11
+ m_sd = mock_model(Services::ServiceDefinition)
12
+ m_sd.should_receive(:valid?).and_return(true)
13
+ m_sd.should_receive(:save)
14
+
15
+ m_sd_rel = double("ServiceDefinitionRelationship")
16
+ m_sd_rel.should_receive(:new).with(params).and_return(m_sd)
17
+
18
+ third_party.should_receive(:service_definitions).and_return(m_sd_rel)
19
+
20
+ expect(third_party.create(params)).to be(m_sd)
21
+ end
22
+
23
+ it "should create the service definition but not save it if is invalid" do
24
+ params = {}
25
+
26
+ m_sd = mock_model(Services::ServiceDefinition)
27
+ m_sd.should_receive(:valid?).and_return(false)
28
+ m_sd.should_not_receive(:save)
29
+
30
+ m_sd_rel = double("ServiceDefinitionRelationship")
31
+ m_sd_rel.should_receive(:new).with(params).and_return(m_sd)
32
+
33
+ third_party.should_receive(:service_definitions).and_return(m_sd_rel)
34
+
35
+ expect(third_party.create(params)).to be(m_sd)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ServiceDefinitionUpdater do
4
+ let(:service_definition) { Services::ServiceDefinition.new.tap { | am | am.extend Services::ServiceDefinitionUpdater } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the ServiceDefinition object with the specified parameters" do
9
+ params = {}
10
+ service_definition.should_receive(:update_attributes).with(params).and_return(service_definition)
11
+ expect(service_definition.update(params)).to be(service_definition)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ServiceInvoker do
4
+ let(:service) { Services::Service.new.tap { | svc | svc.extend Services::ServiceInvoker } }
5
+
6
+ context '#invoke' do
7
+
8
+ it "should invoke the service for each service definition owned by the service" do
9
+
10
+ m_sd1 = mock_model(Services::ServiceDefinition)
11
+ m_sd1.should_receive(:ayl_send_opts).with(:invoke, priority: 100, time_to_run: 3600)
12
+ m_sd2 = mock_model(Services::ServiceDefinition)
13
+ m_sd2.should_receive(:ayl_send_opts).with(:invoke, priority: 100, time_to_run: 3600)
14
+
15
+ service.should_receive(:service_definitions).and_return([ m_sd1, m_sd2 ])
16
+
17
+ service.invoke
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::ServiceUpdater do
4
+ let(:service) { Services::Service.new.tap { | svc | svc.extend Services::ServiceUpdater } }
5
+
6
+ context '#update' do
7
+
8
+ it "should update the attributes of the services from the parameters" do
9
+ params = { name: 'the service' }
10
+
11
+ service.should_receive(:update_attributes).with(params)
12
+
13
+ expect(service.update(params)).to be(service)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::SltcBaselineRequestor do
4
+ let(:configured_account) { Services::ConfiguredAccount.new.tap { | ca | ca.extend Services::SltcBaselineRequestor } }
5
+
6
+ context'#request_baseline_params' do
7
+
8
+ it "should request a baseline from SLTC" do
9
+ params = {
10
+ provider_id: 9,
11
+ uploaded_before: '2013-11-10',
12
+ uploaded_after: '2013-10-10'
13
+ }
14
+
15
+ m_si = double("ServiceImplementation")
16
+ m_si.
17
+ should_receive(:request_baseline).
18
+ with(configured_account, 9, Time.parse(params[:uploaded_after]), Time.parse(params[:uploaded_before]))
19
+
20
+ m_sd = mock_model(Services::ServiceDefinition)
21
+ m_sd.should_receive(:service_implementation).and_return(m_si)
22
+
23
+ configured_account.should_receive(:service_definition).and_return(m_sd)
24
+
25
+ configured_account.request_baseline(params)
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Services::SltcProviderLister do
4
+ let(:configured_account) { Services::ConfiguredAccount.new.tap { | ca | ca.extend Services::SltcProviderLister } }
5
+
6
+ context '#list_providers' do
7
+
8
+ it "should request the list of providers for the configured account from SLTC" do
9
+ provider_list = [ { 'id' => 9, 'name' => 'facility' } ]
10
+
11
+ m_api = double("SltcApi")
12
+ m_api.should_receive(:list_providers).and_return(provider_list)
13
+
14
+ m_si = double("ServiceImplementation")
15
+ m_si.should_receive(:api_impl).with(configured_account).and_return(m_api)
16
+
17
+ m_sd = mock_model(Services::ServiceDefinition)
18
+ m_sd.should_receive(:service_implementation).and_return(m_si)
19
+
20
+ configured_account.should_receive(:service_definition).and_return(m_sd)
21
+
22
+ expect(configured_account.list_providers).to eq(provider_list)
23
+ end
24
+
25
+ end
26
+
27
+ end