def actions(): app = application.get_app() for action in app.actions: yield action for plugin in plugins.plugins(): for action in plugin.actions: yield action
def write_to_many_files(self, data): app_dir = application.get_app().directory() for listname in data: filepath = os.path.abspath( os.path.join(app_dir, 'data', 'lookuplists', '{0}.json'.format(listname))) contents = {listname: data[listname]} self.write_to_file(contents, filepath)
def styles(): app = application.get_app() for style in app.get_styles(): if style.endswith(".scss"): mime_type = "text/x-scss" else: mime_type = "text/css" yield style, mime_type
def yield_property(property_name): app = application.get_app() app_and_plugins = itertools.chain(plugins.OpalPlugin.list(), [app]) for plugin in app_and_plugins: excluded_tracking_prefixes = getattr(plugin, property_name, []) for i in excluded_tracking_prefixes: yield i
def from_component(self, component): # Start with the initial lookuplists.json filename = ffs.Path(LOOKUPLIST_LOCATION.format(component.directory())) self.load(self.from_path(filename)) # then work throught the lookuplists we know about for lookuplist in lookuplists.LookupList.__subclasses__(): path = ffs.Path("{0}/data/lookuplists/{1}.json".format( application.get_app().directory(), lookuplist.get_api_name())) self.load(self.from_path(path))
def test_from_component(self, path): c = loader.Command() c.from_component(application.get_app()) calls = [c[0][0] for c in path.call_args_list] expected = [ 'data/lookuplists/lookuplists.json', 'data/lookuplists/drug.json', 'data/lookuplists/condition.json' ] for e in expected: self.assertTrue(len([c for c in calls if c.endswith(e)]) == 1)
def write_to_many_files(self, data): app_dir = application.get_app().directory() for listname in data: filepath = os.path.abspath( os.path.join( app_dir, 'data', 'lookuplists', '{0}.json'.format(listname) ) ) contents = {listname: data[listname]} self.write_to_file(contents, filepath)
def from_component(self, component): # Start with the initial lookuplists.json filename = ffs.Path(LOOKUPLIST_LOCATION.format(component.directory())) self.load(self.from_path(filename)) # then work throught the lookuplists we know about for lookuplist in lookuplists.LookupList.__subclasses__(): path = ffs.Path("{0}/data/lookuplists/{1}.json".format( application.get_app().directory(), lookuplist.get_api_name() )) self.load(self.from_path(path))
def test_from_component(self, path): c = loader.Command() c.from_component(application.get_app()) calls = [c[0][0] for c in path.call_args_list] expected = [ os.path.join('data', 'lookuplists', 'lookuplists.json'), os.path.join('data', 'lookuplists', 'drug.json'), os.path.join('data', 'lookuplists', 'condition.json'), ] for e in expected: self.assertTrue(len([c for c in calls if c.endswith(e)]) == 1)
def menu(context): """ Render the menu for this application. """ context = copy.copy(context) app = application.get_app() menu = app.get_menu(user=context['user']) context.dicts.append({ 'menu': menu, }) return context
def __init__(self, user=None): self.user = user self.items = [] from opal.core import application, plugins app = application.get_app() # If we don't += this here, we start appending to the # list attached to the active Application class. # Which is suboptimal. self.items = app.get_menu_items(self.user) for plugin in plugins.OpalPlugin.list(): self.items.extend(plugin.get_menu_items(self.user))
def __init__(self, user=None): self.user = user self.items = [] from opal.core import application, plugins app = application.get_app() # If we don't += this here, we start appending to the # list attached to the active Application class. # Which is suboptimal. app_items = app.get_menu_items(user=self.user) warnthem = """ Declaring Opal menu items as python dicts will no longer work in Opal 0.9.0. Menu items should be instances of opal.core.menus.MenuItem You should convert {0} Please consult the Opal documentation on menus for more information. """ for item in app_items: if isinstance(item, MenuItem): self.items.append(item) else: self.items.append(MenuItem(**item)) warnings.warn(warnthem.format(item), DeprecationWarning, stacklevel=2) for plugin in plugins.OpalPlugin.list(): for item in plugin.menuitems: if isinstance(item, MenuItem): self.items.append(item) else: self.items.append(MenuItem(**item)) warnings.warn(warnthem.format(item), DeprecationWarning, stacklevel=2)
from rest_framework import routers, status, viewsets from rest_framework.response import Response from opal.models import ( Episode, Synonym, Patient, PatientRecordAccess, PatientSubrecord ) from opal.core import application, exceptions, metadata, plugins, schemas from opal.core.lookuplists import LookupList from opal.utils import stringport, camelcase_to_underscore from opal.core.subrecords import subrecords from opal.core.views import _get_request_data, _build_json_response from opal.core.patient_lists import ( PatientList, TaggedPatientListMetadata, FirstListMetadata ) app = application.get_app() # TODO This is stupid - we can fully deprecate this please? try: options = stringport(settings.OPAL_OPTIONS_MODULE) micro_test_defaults = options.micro_test_defaults except AttributeError: class options: model_names = [] micro_test_defaults = [] class OPALRouter(routers.DefaultRouter): def get_default_base_name(self, viewset): name = getattr(viewset, 'base_name', None) if name is None: return routers.DefaultRouter.get_default_base_name(self, viewset)
def items(): app = application.get_app() for i in app.menuitems: yield i
from django.contrib.contenttypes.models import ContentType from rest_framework import routers, status, viewsets from rest_framework.permissions import IsAuthenticated from opal.models import ( Episode, Synonym, Patient, PatientRecordAccess, PatientSubrecord, UserProfile ) from opal.core import application, exceptions, metadata, plugins, schemas from opal.core.lookuplists import LookupList from opal.core.subrecords import subrecords from opal.core.views import json_response from opal.core.patient_lists import PatientList app = application.get_app() class OPALRouter(routers.DefaultRouter): def get_default_base_name(self, viewset): name = getattr(viewset, 'base_name', None) if name is None: return routers.DefaultRouter.get_default_base_name(self, viewset) return name router = OPALRouter() def item_from_pk(fn): """
def scripts(): app = application.get_app() for javascript in app.javascripts: yield javascript
def test_created_with_the_default_episode(self): _, episode = self.new_patient_and_episode_please() self.assertEqual(application.get_app().default_episode_category, episode.category_name)
def scripts(): app = application.get_app() for javascript in app.core_javascripts[namespace]: yield javascript
def test_get_app(self, subclasses): mock_app = MagicMock('Mock App') subclasses.return_value = [mock_app] self.assertEqual(mock_app, application.get_app())
def items(): app = application.get_app() for i in app.get_menu_items(user=context['user']): yield i
def opal_angular_deps(): app = application.get_app() return dict(deps=app.get_all_angular_module_deps())
def test_created_with_the_default_episode(self): _, episode = self.new_patient_and_episode_please() self.assertEqual( application.get_app().default_episode_category, episode.category_name )
def get_default_episode_type(): app = application.get_app() return app.default_episode_category
def styles(): app = application.get_app() for style in app.get_styles(): yield style