def test_no_risk_partial_patient(self): """ Test that the server returns the score and clinical risk in the message for patient endpoint """ for wombo_combo in self.combinations: route_under_test = \ route_manager.get_route('json_patient_form_action') self.assertIsInstance(route_under_test, Route) patient_list = self.mock_get_patients() patient_id = patient_list[0].get('id') api_pool = self.registry('nh.eobs.api') activity_pool = self.registry('nh.activity') # mock out api.create_activity def mock_create_activity(*args, **kwargs): return 1 api_pool._patch_method('create_activity_for_patient', mock_create_activity) # mock out api.complete def mock_complete(*args, **kwargs): return True api_pool._patch_method('complete', mock_complete) # mock out search for triggered activities def mock_activity_search(*args, **kwargs): return [] activity_pool._patch_method('search', mock_activity_search) activity_pool._patch_method('read', mock_activity_search) test_resp = requests.post( '{0}{1}/patient/submit_ajax/ews/{2}'.format( route_manager.BASE_URL, route_manager.URL_PREFIX, patient_id), data=wombo_combo, cookies=self.auth_resp.cookies) api_pool._revert_method('create_activity_for_patient') api_pool._revert_method('complete') activity_pool._revert_method('search') activity_pool._revert_method('read') self.assertEqual(test_resp.status_code, 200) self.assertEqual(test_resp.headers['content-type'], 'application/json') patient_data = json.loads(test_resp.content) patient_message = patient_data.get('description') self.assertEqual( patient_message, '<strong>At least No clinical risk</strong>, ' 'real risk may be higher <br>' '<strong>At least 0 NEWS score</strong>, ' 'real NEWS score may be higher<br>' 'This Partial Observation will not update the NEWS score and ' 'clinical risk of the patient')
def test_high_risk_partial_task(self): """ Test submitting a partial that would score low clinical risk on task endpoint """ route_under_test = \ route_manager.get_route('json_task_form_action') self.assertIsInstance(route_under_test, Route) api_pool = self.registry('nh.eobs.api') activity_pool = self.registry('nh.activity') # mock out api.complete def mock_complete(*args, **kwargs): return True api_pool._patch_method('complete', mock_complete) # mock out search for triggered activities def mock_activity_search(*args, **kwargs): return [] activity_pool._patch_method('search', mock_activity_search) activity_pool._patch_method('read', mock_activity_search) test_resp = requests.post('{0}{1}/tasks/submit_ajax/ews/{2}'.format( route_manager.BASE_URL, route_manager.URL_PREFIX, 666), data=self.HIGH_PARTIAL, cookies=self.auth_resp.cookies) api_pool._revert_method('complete') activity_pool._revert_method('search') activity_pool._revert_method('read') self.assertEqual(test_resp.status_code, 200) self.assertEqual(test_resp.headers['content-type'], 'application/json') patient_data = json.loads(test_resp.content) patient_message = patient_data.get('description') self.assertEqual( patient_message, '<strong>At least High clinical risk</strong>, ' 'real risk may be higher <br>' '<strong>At least 7 NEWS score</strong>, ' 'real NEWS score may be higher<br>' 'This Partial Observation will not update the NEWS score and ' 'clinical risk of the patient')
methods=['GET'], url_prefix='/mobile' ) task_list = EobsRoute( 'task_list', '/tasks/', methods=['GET'], url_prefix='/mobile' ) single_task = EobsRoute( 'single_task', '/task/<task_id>', methods=['GET'], url_prefix='/mobile' ) if not route_manager.get_route('single_patient'): route_manager.add_route(single_patient) if not route_manager.get_route('patient_list'): route_manager.add_route(patient_list) if not route_manager.get_route('single_task'): route_manager.add_route(single_task) if not route_manager.get_route('task_list'): route_manager.add_route(task_list) def abort_and_redirect(url): """ Aborts and redirects to ``url``.
# -*- coding: utf-8 -*- from openerp import http from openerp.addons.nh_eobs_api.controllers.route_api import route_manager from openerp.addons.nh_eobs_api.routing import ResponseJSON from openerp.addons.nh_eobs_api.routing import Route from openerp.addons.nh_eobs_mobile.controllers.main import MobileFrontend from openerp.http import request if not route_manager.get_route('rapid_tranq'): route_toggle_rapid_tranq = Route( 'rapid_tranq', '/patient/<patient_id>/rapid_tranq', methods=['GET', 'POST'], url_prefix='/mobile' ) route_manager.add_route(route_toggle_rapid_tranq) class MobileFrontendMentalHealth(MobileFrontend): @http.route(**route_manager.expose_route('rapid_tranq')) def rapid_tranq(self, *args, **kwargs): """ Endpoint for reading and writing the `rapid_tranq` field on a patient's spell. Let's the API model create the JSON encoded response and simply wraps it in a response object to be returned to the client. :param args: :param kwargs:
# -*- coding: utf-8 -*- from openerp import http from openerp.addons.nh_eobs_api.controllers.route_api import route_manager from openerp.addons.nh_eobs_api.routing import ResponseJSON from openerp.addons.nh_eobs_api.routing import Route from openerp.addons.nh_eobs_mobile.controllers.main import MobileFrontend from openerp.http import request if not route_manager.get_route('rapid_tranq'): route_toggle_rapid_tranq = Route('rapid_tranq', '/patient/<patient_id>/rapid_tranq', methods=['GET', 'POST'], url_prefix='/mobile') route_manager.add_route(route_toggle_rapid_tranq) class MobileFrontendMentalHealth(MobileFrontend): @http.route(**route_manager.expose_route('rapid_tranq')) def rapid_tranq(self, *args, **kwargs): """ Endpoint for reading and writing the `rapid_tranq` field on a patient's spell. Let's the API model create the JSON encoded response and simply wraps it in a response object to be returned to the client. :param args: :param kwargs: :return: """ api_model = request.registry('nh.eobs.api')
'/patient/<patient_id>', methods=['GET'], url_prefix='/mobile') patient_list = EobsRoute('patient_list', '/patients/', methods=['GET'], url_prefix='/mobile') task_list = EobsRoute('task_list', '/tasks/', methods=['GET'], url_prefix='/mobile') single_task = EobsRoute('single_task', '/task/<task_id>', methods=['GET'], url_prefix='/mobile') if not route_manager.get_route('single_patient'): route_manager.add_route(single_patient) if not route_manager.get_route('patient_list'): route_manager.add_route(patient_list) if not route_manager.get_route('single_task'): route_manager.add_route(single_task) if not route_manager.get_route('task_list'): route_manager.add_route(task_list) def abort_and_redirect(url): """ Aborts and redirects to ``url``.