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,50 @@
1
+ module Services
2
+
3
+ class PublicKeysController < Services::ApplicationController
4
+ attr_reader :public_key
5
+
6
+ respond_to :json
7
+
8
+ before_action :must_have_public_key, only: [ :show, :update, :destroy ]
9
+
10
+ def index
11
+ @public_keys = PublicKey.order("valid_until DESC").limit(MAX_LIST_LENGTH)
12
+ end
13
+
14
+ def create
15
+ pk = CreatePublicKeyContext.call(safe_params)
16
+ if pk.errors.empty?
17
+ render json: { id: pk.id }
18
+ else
19
+ render json: { validation_error: pk.errors.full_messages }, status: 403
20
+ end
21
+ end
22
+
23
+ def update
24
+ UpdatePublicKeyContext.call(public_key, safe_params)
25
+ if public_key.errors.empty?
26
+ render json: { id: public_key.id }
27
+ else
28
+ render json: { validation_error: public_key.errors.full_messages }, status: 403
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ public_key.destroy
34
+ render json: { id: public_key.id }
35
+ end
36
+
37
+ private
38
+
39
+ def safe_params
40
+ params.require(:public_key).permit(:name, :valid_until, :key_file)
41
+ end
42
+
43
+ def must_have_public_key
44
+ @public_key = PublicKey.where(id: params[:id]).first
45
+ render json: { error: "No Public Key found with id: #{params[:id]}" } if @public_key.blank?
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ module Services
2
+
3
+ class ServiceBaseController < Services::ApplicationController
4
+
5
+ attr_reader :service
6
+
7
+ before_filter :must_have_service
8
+
9
+ private
10
+
11
+ def must_have_service
12
+ @service = Service.where(id: params[:service_id]).first
13
+ render json: { error: "No service with id: #{params[:service_id]}" }, status: 404 if @service.blank?
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,31 @@
1
+ module Services
2
+
3
+ class ServiceDefinitionBaseController < Services::ApplicationController
4
+
5
+ attr_reader :service_definition, :parent
6
+
7
+ before_filter :must_have_third_party_or_service
8
+ before_filter :must_have_service_definition
9
+
10
+ private
11
+
12
+ def must_have_third_party_or_service
13
+ if params[:third_party_id].present?
14
+ @parent = ThirdParty.where(id: params[:third_party_id]).first
15
+ render json: { error: "No third party with id: #{params[:third_party_id]}" }, status: 404 if @parent.blank?
16
+ elsif params[:service_id].present?
17
+ @parent = Service.where(id: params[:service_id]).first
18
+ render json: { error: "No service with id: #{params[:service_id]}" }, status: 404 if @parent.blank?
19
+ else
20
+ render json: { error: "Must specify a parent of the service definition" }, status: 404
21
+ end
22
+ end
23
+
24
+ def must_have_service_definition
25
+ @service_definition = parent.service_definitions.where(id: params[:service_definition_id]).first
26
+ render json: { error: "No service definition with id: #{params[:service_definition_id]}" }, status: 404 if @service_definition.blank?
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,59 @@
1
+ module Services
2
+
3
+ class ServiceDefinitionsController < Services::ServiceDefinitionBaseController
4
+
5
+ respond_to :json
6
+
7
+ skip_before_filter :must_have_service_definition
8
+ before_filter :must_have_service_definition_id, only: [ :show, :update, :destroy ]
9
+
10
+ def index
11
+ @service_definitions = parent.service_definitions.includes(:credentials).limit(MAX_LIST_LENGTH)
12
+ end
13
+
14
+ def show
15
+ # Nothing necessary
16
+ end
17
+
18
+ def create
19
+ svc_def = CreateServiceDefinitionContext.call(parent, safe_sd_params, safe_cred_params)
20
+ if svc_def.errors.empty?
21
+ render json: { id: svc_def.id }
22
+ else
23
+ render json: { validation_error: svc_def.errors.full_messages }, status: 403
24
+ end
25
+ end
26
+
27
+ def update
28
+ UpdateServiceDefinitionContext.call(service_definition, safe_sd_params, safe_cred_params)
29
+ if service_definition.errors.empty?
30
+ render json: { id: service_definition.id }
31
+ else
32
+ render json: { validation_error: service_definition.errors.full_messages }, status: 403
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ service_definition.destroy
38
+ render json: { id: service_definition.id }
39
+ end
40
+
41
+ private
42
+
43
+ def safe_sd_params
44
+ params.require(:service_definition).permit(:service_id, :hostname, :port, :base_uri, :username, :service_class)
45
+ end
46
+
47
+ def safe_cred_params
48
+ return {} if params[:credential].blank?
49
+ params.require(:credential).permit(:password, :token)
50
+ end
51
+
52
+ def must_have_service_definition_id
53
+ @service_definition = parent.service_definitions.where(id: params[:id]).includes(:credentials).first
54
+ render json: { error: "No service definition with id: #{params[:id]}" }, status: 404 if @service_definition.blank?
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,56 @@
1
+ module Services
2
+
3
+ class ServicesController < Services::ApplicationController
4
+ attr_reader :service
5
+
6
+ respond_to :json
7
+
8
+ before_filter :must_have_service, only: [ :show, :update, :invoke ]
9
+
10
+ def index
11
+ @services = Service.limit(MAX_LIST_LENGTH)
12
+ end
13
+
14
+ def show
15
+ end
16
+
17
+ def create
18
+ svc = CreateServiceContext.call(safe_params)
19
+ if svc.errors.empty?
20
+ render json: { id: svc.id }
21
+ else
22
+ render json: { validation_error: svc.errors.full_messages }, status: 403
23
+ end
24
+ end
25
+
26
+ def update
27
+ UpdateServiceContext.call(service, safe_params)
28
+ if service.errors.empty?
29
+ render json: { id: service.id }
30
+ else
31
+ render json: { validation_error: service.errors.full_messages }, status: 403
32
+ end
33
+ end
34
+
35
+ def invoke
36
+ InvokeServiceContext.call(service)
37
+
38
+ render json: { message: "Service '#{service.name}' invoked in the background" }
39
+ rescue Exception => ex
40
+ render json: { error: "Error invoking Service '#{service.name}': #{ex.message}" }
41
+ end
42
+
43
+ private
44
+
45
+ def safe_params
46
+ params.require(:service).permit(:name, :key)
47
+ end
48
+
49
+ def must_have_service
50
+ @service = Service.where(id: params[:id]).first
51
+ render json: { error: "No Service found with id: #{params[:id]}" } if @service.blank?
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,15 @@
1
+ module Services
2
+
3
+ class SltcProvidersController < Services::ApplicationController
4
+
5
+ respond_to :json
6
+
7
+ def index
8
+ ca = ConfiguredAccount.find params[:configured_account_id]
9
+
10
+ @providers = ListSltcProvidersContext.call(ca)
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,74 @@
1
+ module Services
2
+
3
+ class SltcRegistrationsController < Services::ApplicationController
4
+ attr_reader :registration
5
+ attr_reader :valid_registration_request
6
+ attr_reader :jwt
7
+
8
+ skip_before_action :restrict_access, only: [ :create ]
9
+ before_action :must_have_sltc_registration, only: [ :complete ]
10
+ before_action :validate_registration_request, only: [ :create ]
11
+
12
+ respond_to :json
13
+
14
+ def index
15
+ @registrations = params[:status].present? ? SltcRegistration.where(status: params[:status]).order("created_at DESC").limit(MAX_LIST_LENGTH) : SltcRegistration.order("created_at DESC").limit(MAX_LIST_LENGTH)
16
+ end
17
+
18
+ def complete
19
+ CompleteSltcRegistrationProcessContext.call(registration, completion_params)
20
+ render json: { id: registration.id }
21
+ end
22
+
23
+ def create
24
+ # We currently deal only with type 1
25
+ if valid_registration_request[:type] != 1
26
+ ServicesMailer.notify_sltc_client_registration_invalid_request_type(valid_registration_request[:type], jwt).deliver
27
+ render(nothing: true, status:500) && return
28
+ end
29
+
30
+ result = CreateSltcRegistrationContext.call(safe_params(valid_registration_request))
31
+ if result.errors.empty?
32
+ render nothing: true, status: 200
33
+ else
34
+ ServicesMailer.notify_sltc_client_registration_validation_errors(result, jwt).deliver
35
+ render nothing: true, status: 500
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def completion_params
42
+ allowed_params = [ :third_party_id, :service_definition_id, :account_id, :baseline_days, :configure_only ]
43
+ params.slice(*allowed_params)
44
+ end
45
+
46
+ def safe_params(registration_request_params)
47
+ allowed_params = [ :company_name, :auth_password, :auth_username, :initiated_by, :timestamp ]
48
+ registration_request_params.slice(*allowed_params)
49
+ end
50
+
51
+ def must_have_sltc_registration
52
+ @registration = SltcRegistration.where(id: params[:id]).first if params[:id].present?
53
+ render json: { error: "No Sltc Registration with id: #{params[:id]}" }, status: 404 unless @registration.present?
54
+ end
55
+
56
+ def validate_registration_request
57
+ # The inbound request provides a JWT (JSon Web Token) which is a signed
58
+ # JSON request. We must grab the request body, decode and verify it
59
+ # against the public key provided by SLTC.
60
+ @jwt = request.body.read
61
+ request = Sandal.decode_token(@jwt) do | header |
62
+ pk = PublicKey.active.where(name: header['kid']).first
63
+ raise "No matching public key found for: #{header['kid']}" unless pk.present?
64
+ Sandal::Sig::RS256.new(pk.key)
65
+ end
66
+ @valid_registration_request = ActiveSupport::HashWithIndifferentAccess.new(request)
67
+ rescue => ex
68
+ ServicesMailer.notify_sltc_client_registration_request_invalid(@jwt, ex).deliver
69
+ render nothing: true, status: 400
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,17 @@
1
+ module Services
2
+
3
+ module StatusMasking
4
+ STATUS_MASK = 0x0f
5
+ NEGATE_MASK = 0x10
6
+
7
+ def determine_status_operator(status_param)
8
+ return [] if status_param.nil?
9
+
10
+ raw_status = status_param.to_i
11
+ status = raw_status & STATUS_MASK
12
+ operator = (raw_status & NEGATE_MASK) != 0 ? "!=" : "="
13
+ [ status, operator ]
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,47 @@
1
+ module Services
2
+
3
+ class ThirdPartiesController < Services::ApplicationController
4
+ attr_reader :third_party
5
+ respond_to :json
6
+
7
+ before_filter :must_have_third_party, only: [ :show, :update ]
8
+
9
+ def index
10
+ @third_parties = ThirdParty.limit(MAX_LIST_LENGTH)
11
+ end
12
+
13
+ def show
14
+ end
15
+
16
+ def create
17
+ tp = CreateThirdPartyContext.call(safe_params)
18
+ if tp.errors.empty?
19
+ render json: { id: tp.id }
20
+ else
21
+ render json: { validation_error: tp.errors.full_messages }, status: 403
22
+ end
23
+ end
24
+
25
+ def update
26
+ UpdateThirdPartyContext.call(third_party, safe_params)
27
+ if third_party.errors.blank?
28
+ render json: { id: third_party.id }
29
+ else
30
+ render json: { validation_error: third_party.errors.full_messages }, status: 403
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def safe_params
37
+ params.require(:third_party).permit(:name, :key, :contact_email)
38
+ end
39
+
40
+ def must_have_third_party
41
+ @third_party = ThirdParty.where(id: params[:id]).first
42
+ render json: { error: "No third party with id: #{params[:id]}" }, status: 404 if @third_party.blank?
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,17 @@
1
+ module Services
2
+
3
+ class ThirdPartyBaseController < Services::ApplicationController
4
+ attr_reader :third_party
5
+
6
+ before_filter :must_have_third_party
7
+
8
+ private
9
+
10
+ def must_have_third_party
11
+ @third_party = ThirdParty.where(id: params[:third_party_id]).first
12
+ render json: { error: "No third party with id: #{params[:third_party_id]}" }, status: 404 if @third_party.blank?
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ module Services
2
+
3
+ class ValidationController < Services::ApplicationController
4
+
5
+ respond_to :json
6
+
7
+ def valid_object
8
+ object_type = params[:object_type]
9
+ object_id = params[:object_id]
10
+
11
+ exists = eval(object_type).where("id = ?", object_id).count > 0
12
+ render json: { exists: exists }
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,8 @@
1
+ module Services
2
+ module ApplicationHelper
3
+ def american_date_time(date)
4
+ return nil if date.nil?
5
+ (date.is_a?(Date) || date.is_a?(Time)) ? (date.is_a?(Time) ? date.in_time_zone(DISPLAY_TIME_ZONE).strftime("%-m/%-d/%Y %H:%M:%S") : date.strftime("%-m/%-d/%Y %H:%M:%S")) : date
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ module Services
2
+ module AssessmentRequestHelper
3
+
4
+ def assessment_request_status(status)
5
+ status_name = 'Unknown'
6
+ case status
7
+ when Services::AssessmentRequest::STATUS_AVAILABLE
8
+ status_name = 'Available'
9
+ when Services::AssessmentRequest::STATUS_COMPLETED
10
+ status_name = 'Downloaded'
11
+ when Services::AssessmentRequest::STATUS_EMPTY
12
+ status_name = 'Empty'
13
+ when Services::AssessmentRequest::STATUS_ERROR
14
+ status_name = 'Error'
15
+ end
16
+ "(#{status}) #{status_name}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Services
2
+ module AvailableFilesHelper
3
+
4
+ def available_file_status(status)
5
+ status_name = 'Unknown'
6
+ case status
7
+ when Services::AvailableFile::STATUS_AVAILABLE
8
+ status_name = 'Available'
9
+ when Services::AvailableFile::STATUS_DOWNLOADED
10
+ status_name = 'Downloaded'
11
+ when Services::AvailableFile::STATUS_CLEARED
12
+ status_name = 'Cleared'
13
+ when Services::AvailableFile::STATUS_INVALID
14
+ status_name = 'Invalid'
15
+ when Services::AvailableFile::STATUS_MISSING
16
+ status_name = 'Missing'
17
+ when Services::AvailableFile::STATUS_UPLOADED
18
+ status_name = 'Uploaded'
19
+ when Services::AvailableFile::STATUS_UPLOAD_ERROR
20
+ status_name = 'Upload Error'
21
+ when Services::AvailableFile::STATUS_DELETED
22
+ status_name = 'Deleted'
23
+ end
24
+ "(#{status}) #{status_name}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module Services
2
+ module MdsPullAccountsHelper
3
+
4
+ def mds_pull_account_status(status)
5
+ status_name = 'Unknown'
6
+ case status
7
+ when Services::MdsPullAccount::STATUS_NEW
8
+ status_name = 'New'
9
+ when Services::MdsPullAccount::STATUS_PROVIDERS_IDENTIFIED
10
+ status_name = 'Providers Identified'
11
+ when Services::MdsPullAccount::STATUS_ASSESSMENTS_REQUESTED
12
+ status_name = 'Assessments Requested'
13
+ when Services::MdsPullAccount::STATUS_FILES_IDENTIFIED
14
+ status_name = 'Files Identified'
15
+ when Services::MdsPullAccount::STATUS_FILES_DOWNLOADED
16
+ status_name = 'Files Downloaded'
17
+ when Services::MdsPullAccount::STATUS_SUBMITTED_TO_ABAQIS
18
+ status_name = 'Submitted'
19
+ when Services::MdsPullAccount::STATUS_FILE_SYSTEM_CLEAN
20
+ status_name = 'File System Clean'
21
+ when Services::MdsPullAccount::STATUS_REMOTE_CLEAN
22
+ status_name = 'Remote Clean'
23
+ end
24
+ "(#{status}) #{status_name}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Services
2
+ module SltcRegistrationsHelper
3
+
4
+ def sltc_registration_status(status)
5
+ status_name = 'Unknown'
6
+ case status
7
+ when Services::SltcRegistration::STATUS_NEW
8
+ status_name = 'New'
9
+ when Services::SltcRegistration::STATUS_REGISTERED
10
+ status_name = 'Completed'
11
+ end
12
+ "(#{status}) #{status_name}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ class ServicesMailer < ActionMailer::Base
2
+
3
+ default :to => $system_mail_recipients, :from => "abaqis.dev@providigm.com"
4
+
5
+ def burying_job(tp_mds_pull_account)
6
+ @mds_pull_account = tp_mds_pull_account
7
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
8
+
9
+ mail(subject: "Burying a job on #{@application_host}")
10
+ end
11
+
12
+ def delaying_job(tp_mds_pull_account)
13
+ @mds_pull_account = tp_mds_pull_account
14
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
15
+
16
+ mail(subject: "Delaying a job on #{@application_host}")
17
+ end
18
+
19
+ def notify_support_about_no_mds_pull
20
+ mail(:subject => "There was no record of an MDS pull today.")
21
+ end
22
+
23
+ def notify_sltc_provider_changes(provider_deltas)
24
+ @provider_deltas = provider_deltas
25
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
26
+ mail(:subject => "SLTC: Changes to provider assignments on #{@application_host}")
27
+ end
28
+
29
+ def notify_sltc_client_registration(registration)
30
+ @registration = registration
31
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
32
+ mail subject: "Provider '#{registration.company_name}' has registered with SimpleLTC on #{@application_host}"
33
+ end
34
+
35
+ def notify_sltc_client_registration_request_invalid(jwt, ex)
36
+ @jwt = jwt
37
+ @ex = ex
38
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
39
+ mail subject: "Invalid SLTC registration request on #{@application_host}"
40
+ end
41
+
42
+ def notify_sltc_client_registration_invalid_request_type(mt, jwt)
43
+ @jwt = jwt
44
+ @mt = mt
45
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
46
+ mail subject: "Invalid SLTC registration request type received on #{@application_host}"
47
+ end
48
+
49
+ def notify_sltc_client_registration_validation_errors(registration, jwt)
50
+ @registration = registration
51
+ @jwt = jwt
52
+ @application_host = Services::ApplicationApi.api_impl.get_application_host
53
+ mail subject: "SLTC registration request has validation errors on #{@application_host}"
54
+ end
55
+
56
+
57
+ end
@@ -0,0 +1,51 @@
1
+ module Services
2
+
3
+ class AbaqisMdsPush < MdsPush
4
+
5
+ URI_TEMPLATE = '%s/stagei/mds30_composite_file'
6
+
7
+ def self.service_impl
8
+ svc_def = service_definition
9
+
10
+ svc_def.service_implementation if svc_def.present?
11
+ end
12
+
13
+ def self.service_definition
14
+ ServiceDefinition.where(service_class: self.name.split("::").last).first
15
+ end
16
+
17
+ def self.configured_account(account_id)
18
+ svc_def = service_definition
19
+ svc_def.configured_accounts.where(account_id: account_id).first if svc_def.present?
20
+ end
21
+
22
+ def submit_to_service(available_file)
23
+ account_id = available_file.configured_account.account_id
24
+ conf_acct = service_definition.configured_accounts.where(account_id: account_id).first
25
+ raise "Account '#{account_id}' is not configured for the MDS Web Service" if conf_acct.blank?
26
+ raise "Account '#{account_id}' is not enabled for the MDS Web Service" unless conf_acct.enabled?
27
+ mdsws_password = conf_acct.credentials.first.try(:password)
28
+ raise "Account '#{account_id}' does not have a password defined for the MDS Web Service" if mdsws_password.blank?
29
+
30
+ response = RestClient.post(url,
31
+ { :composite_file => File.new(available_file.actual_file_path, 'rb') },
32
+ { 'account-id' => account_id,
33
+ 'account-password' => mdsws_password }).body
34
+
35
+ Rails.logger.info response
36
+
37
+ r = MdsWsResponse.parse_xml_response(response)
38
+ if r.status == MdsWsResponse::STATUS_SUCCESS
39
+ available_file.update_attribute :status, AvailableFile::STATUS_UPLOADED
40
+ else
41
+ available_file.update_attributes status: AvailableFile::STATUS_UPLOAD_ERROR, error: r.error_message
42
+ end
43
+ end
44
+
45
+ def url
46
+ format URI_TEMPLATE, service_definition.server_base_url
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,10 @@
1
+ module Services
2
+
3
+ class AccountMapping < ActiveRecord::Base
4
+ belongs_to :third_party
5
+ belongs_to :account
6
+
7
+ validates :account_code, presence: true, length: { maximum: 255 }
8
+ end
9
+
10
+ end
@@ -0,0 +1,19 @@
1
+ module Services
2
+ class ApplicationApi
3
+ include Singleton
4
+
5
+ class << self
6
+ attr_writer :api_impl
7
+
8
+ def api_impl
9
+ @api_impl || self.instance
10
+ end
11
+ end
12
+
13
+ def get_application_host
14
+ "localhost:3000"
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,18 @@
1
+ module Services
2
+
3
+ class AssessmentRequest < ActiveRecord::Base
4
+
5
+ STATUS_AVAILABLE = 0
6
+ STATUS_COMPLETED = 1
7
+ STATUS_EMPTY = 2
8
+ STATUS_ERROR = 3
9
+
10
+ validates :facility_code, presence: true, length: { maximum: 255 }
11
+ validates :request_id, presence: true, length: { maximum: 255 }
12
+
13
+
14
+ scope :available, -> { where(status: STATUS_AVAILABLE) }
15
+
16
+ end
17
+
18
+ end