Пример #1
0
def autodiscover():
    from opal.utils import stringport
    global AUTODISCOVERED

    for a in settings.INSTALLED_APPS:
        stringport(a)
    AUTODISCOVERED = True

    return REGISTRY
Пример #2
0
def autodiscover():
    from opal.utils import stringport
    global AUTODISCOVERED

    for a in settings.INSTALLED_APPS:
        stringport(a)
    AUTODISCOVERED = True

    return REGISTRY
Пример #3
0
def import_from_apps():
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    for app in settings.INSTALLED_APPS:
        try:
            stringport(app + '.referrals')
        except ImportError:
            pass  # not a problem
    global IMPORTED_FROM_APPS
    IMPORTED_FROM_APPS = True
    return
Пример #4
0
def import_from_apps():
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    for app in settings.INSTALLED_APPS:
        try:
            stringport(app + '.referrals')
        except ImportError:
            pass # not a problem
    global IMPORTED_FROM_APPS
    IMPORTED_FROM_APPS = True
    return
Пример #5
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    if not module in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                stringport('{0}.{1}'.format(app, module))
            except ImportError:
                pass # not a problem
        global IMPORTED_FROM_APPS
        IMPORTED_FROM_APPS.add(module)
        return
Пример #6
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    global IMPORTED_FROM_APPS
    if not module in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                stringport('{0}.{1}'.format(app, module))
            except ImportError:
                pass # not a problem
        IMPORTED_FROM_APPS.add(module)
        return
Пример #7
0
def get_study_schemas():
    """
    Return a dict of schemas to be used with our research studies.
    """
    # This has to be here because Django wants to make sure it's the first
    # thing to import models and gets distinctly snippish if you beat it.
    from research.models import ResearchStudy

    research_nurse_schema = stringport(settings.LIST_SCHEMA_RESEARCH_PRACTITIONER)
    scientist_schema = stringport(settings.LIST_SCHEMA_SCIENTIST)

    schemas = collections.defaultdict(dict)
    for study in ResearchStudy.objects.filter(active=True):
        schemas[study.team_name][study.team_name + '_research_practitioner'] = research_nurse_schema
        schemas[study.team_name][study.team_name + '_scientist'] = scientist_schema
    return schemas
Пример #8
0
def create_query(user, criteria):
    """
        gives us a level of indirection to select the search backend we're
        going to use, without this we can get import errors if the module is
        loaded after this module
    """
    if hasattr(settings, "OPAL_SEARCH_BACKEND"):
        return stringport(settings.OPAL_SEARCH_BACKEND)(user, criteria)

    return DatabaseQuery(user, criteria)
Пример #9
0
def create_query(user, criteria):
    """
        gives us a level of indirection to select the search backend we're
        going to use, without this we can get import errors if the module is
        loaded after this module
    """
    if hasattr(settings, "OPAL_SEARCH_BACKEND"):
        query_backend = stringport(settings.OPAL_SEARCH_BACKEND)
        return query_backend(user, criteria)

    return DatabaseQuery(user, criteria)
Пример #10
0
def scaffold(args):
    """
    Create record boilierplates:

    1. Run a south auto migration
    2. Create display templates
    3. Create forms
    """
    app = args.app
    name = find_application_name()
    scaffold_utils._set_settings_module(name)
    sys.path.append(os.path.abspath('.'))

    # 1. Let's run a Django migration
    dry_run = ''
    if args.dry_run:
        dry_run = '--dry-run'

    if not args.nomigrations:
        makemigrations_cmd = "python manage.py makemigrations {app} " \
                             "--traceback {dry_run}"
        makemigrations_cmd = makemigrations_cmd.format(
            app=app, dry_run=dry_run)
        migrate_cmd = 'python manage.py migrate {app} --traceback'.format(
            app=app)

        os.system(makemigrations_cmd)
        if not args.dry_run:
            os.system(migrate_cmd)

    # 2. Let's create some display templates
    from opal.models import Subrecord, EpisodeSubrecord, PatientSubrecord

    models = stringport('{0}.models'.format(app))
    for i in dir(models):
        thing = getattr(models, i)
        if inspect.isclass(thing) and issubclass(thing, Subrecord):
            if thing in [Subrecord, EpisodeSubrecord, PatientSubrecord]:
                continue
            if not thing.get_display_template():
                if args.dry_run:
                    write('No Display template for {0}'.format(thing))
                else:
                    scaffold_utils.create_display_template_for(
                        thing, SCAFFOLDING_BASE
                    )
            if not thing.get_modal_template():
                if args.dry_run:
                    write('No Form template for {0}'.format(thing))
                else:
                    scaffold_utils.create_form_template_for(
                        thing, SCAFFOLDING_BASE
                    )
    return
Пример #11
0
def scaffold(args):
    """
    Create record boilierplates:

    1. Run a south auto migration
    2. Create display templates
    3. Create forms
    """
    app = args.app
    name = find_application_name()
    scaffold_utils._set_settings_module(name)
    sys.path.append(os.path.abspath('.'))

    # 1. Let's run a Django migration
    dry_run = ''
    if args.dry_run:
        dry_run = '--dry-run'

    if not args.nomigrations:
        makemigrations_cmd = "python manage.py makemigrations {app} " \
                             "--traceback {dry_run}"
        makemigrations_cmd = makemigrations_cmd.format(app=app,
                                                       dry_run=dry_run)
        migrate_cmd = 'python manage.py migrate {app} --traceback'.format(
            app=app)

        os.system(makemigrations_cmd)
        if not args.dry_run:
            os.system(migrate_cmd)

    # 2. Let's create some display templates
    from opal.models import Subrecord, EpisodeSubrecord, PatientSubrecord

    models = stringport('{0}.models'.format(app))
    for i in dir(models):
        thing = getattr(models, i)
        if inspect.isclass(thing) and issubclass(thing, Subrecord):
            if thing in [Subrecord, EpisodeSubrecord, PatientSubrecord]:
                continue
            if not thing.get_display_template():
                if args.dry_run:
                    write('No Display template for {0}'.format(thing))
                else:
                    scaffold_utils.create_display_template_for(
                        thing, SCAFFOLDING_BASE)
            if not thing.get_modal_template():
                if args.dry_run:
                    write('No Form template for {0}'.format(thing))
                else:
                    scaffold_utils.create_form_template_for(
                        thing, SCAFFOLDING_BASE)
    return
Пример #12
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    global IMPORTED_FROM_APPS
    if module not in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                target_module = '{0}.{1}'.format(app, module)
                stringport(target_module)
            except ImportError as e:
                expected_errs = [
                    "No module named {0}".format(module),  # Python 2.x
                    "No module named '{0}'".format(target_module)  # Python 3.x
                ]
                if str(e) in expected_errs:
                    continue  # not a problem - we expect this
                raise  # a problem - probably inside the target module.
        IMPORTED_FROM_APPS.add(module)
        return
Пример #13
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.wardrounds
    This way we allow our implementation, or plugins, to define their
    own ward rounds.
    """
    global IMPORTED_FROM_APPS
    if module not in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                target_module = '{0}.{1}'.format(app, module)
                stringport(target_module)
            except ImportError as e:
                expected_errs = [
                    "No module named {0}".format(module),  # Python 2.x
                    "No module named '{0}'".format(target_module)  # Python 3.x
                ]
                if str(e) in expected_errs:
                    continue  # not a problem - we expect this
                raise  # a problem - probably inside the target module.
        IMPORTED_FROM_APPS.add(module)
        return
Пример #14
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.`module`.

    This enables us to ensure that we have autoloaded instances of
    discoverables.
    """
    global IMPORTED_FROM_APPS
    if module not in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                target_module = '{0}.{1}'.format(app, module)
                stringport(target_module)
            except ImportError as e:
                expected_errs = [
                    "No module named {0}".format(module),  # Python 2.x
                    "No module named '{0}'".format(target_module)  # Python 3.x
                ]
                if str(e) in expected_errs:
                    continue  # not a problem - we expect this
                raise  # a problem - probably inside the target module.
        IMPORTED_FROM_APPS.add(module)
        return
Пример #15
0
def import_from_apps(module):
    """
    Iterate through installed apps attempting to import app.`module`.

    This enables us to ensure that we have autoloaded instances of
    discoverables.
    """
    global IMPORTED_FROM_APPS
    if module not in IMPORTED_FROM_APPS:
        for app in settings.INSTALLED_APPS:
            try:
                target_module = '{0}.{1}'.format(app, module)
                stringport(target_module)
            except ImportError as e:
                expected_errs = [
                    "No module named {0}".format(module),  # Python 2.x
                    "No module named '{0}'".format(target_module)  # Python 3.x
                ]
                if str(e) in expected_errs:
                    continue  # not a problem - we expect this
                raise  # a problem - probably inside the target module.
        IMPORTED_FROM_APPS.add(module)
        return
Пример #16
0
    def flows(klass):
        """
        Default implementation of flows()

        Pulls flows defined in the application's flows module,
        plus any flows defined by plugins.
        """
        from opal.core import plugins

        flows = {}
        for plugin in plugins.plugins():
            flows.update(plugin().flows())

        if klass.flow_module is None:
            return flows

        flow = stringport(klass.flow_module)
        flows.update(flow.flows)
        return flows
Пример #17
0
 def test_empty_name_is_valueerror(self):
     with self.assertRaises(ValueError):
         utils.stringport('')
Пример #18
0
 def test_import_perioded_thing(self):
     self.assertEqual(TestCase, utils.stringport('django.test.TestCase'))
Пример #19
0
 def test_import_no_period(self):
     with self.assertRaises(ImportError):
         utils.stringport('wotcha')
Пример #20
0
 def test_import(self):
     import collections
     self.assertEqual(collections, utils.stringport('collections'))
Пример #21
0
 def test_empty_name_is_valueerror(self):
     with self.assertRaises(ValueError):
         utils.stringport('')
Пример #22
0
from django.template.loader import select_template, get_template
from django.template import TemplateDoesNotExist
from django.views.generic import TemplateView, View
from django.views.decorators.http import require_http_methods

from opal import models
from opal.core import application, exceptions, glossolalia
from opal.core.subrecords import episode_subrecords, subrecords
from opal.core.views import LoginRequiredMixin, _get_request_data, _build_json_response
from opal.core.schemas import get_all_list_schema_classes
from opal.utils import camelcase_to_underscore, stringport
from opal.utils.banned_passwords import banned

app = application.get_app()

schema = stringport(app.schema_module)
# 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:
        micro_test_defaults = []

Synonym = models.Synonym


class EpisodeTemplateView(TemplateView):
    def get_column_context(self, **kwargs):
        """
        Return the context for our columns
Пример #23
0
from django.template.loader import select_template, get_template
from django.template import TemplateDoesNotExist
from django.views.generic import TemplateView, View
from django.views.decorators.http import require_http_methods

from opal import models
from opal.core import application, exceptions, glossolalia
from opal.core.subrecords import episode_subrecords, subrecords
from opal.core.views import LoginRequiredMixin, _get_request_data, _build_json_response
from opal.core.schemas import get_all_list_schema_classes
from opal.utils import camelcase_to_underscore, stringport
from opal.utils.banned_passwords import banned

app = application.get_app()

schema = stringport(app.schema_module)
# 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:
        micro_test_defaults = []


Synonym = models.Synonym


class EpisodeTemplateView(TemplateView):
    def get_column_context(self, **kwargs):
Пример #24
0
 def test_import(self):
     import collections
     self.assertEqual(collections, stringport('collections'))
Пример #25
0
from rest_framework import routers, status, viewsets
from rest_framework.response import Response
from opal.models import Episode, Synonym, Team, Macro
from opal.core import application, exceptions, plugins
from opal.core import glossolalia
from opal.core.lookuplists import LookupList
from opal.utils import stringport, camelcase_to_underscore
from opal.core import schemas
from opal.core.subrecords import subrecords
from opal.core.views import _get_request_data, _build_json_response

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)
        return name

router = OPALRouter()
Пример #26
0
 def test_import_perioded_thing(self):
     self.assertEqual(TestCase, utils.stringport('django.test.TestCase'))
Пример #27
0
"""
Utilities for dealing with OPAL Schemas
"""
from opal.utils import stringport
from opal.core.subrecords import subrecords
from opal.core import application, plugins
from opal import models

app = application.get_app()

schema = stringport(app.schema_module)

def serialize_model(model):
    col = {
        'name'        : model.get_api_name(),
        'display_name': model.get_display_name(),
        'single'      : model._is_singleton,
        'advanced_searchable': model._advanced_searchable,
        'fields'      : model.build_field_schema()
        }
    if hasattr(model, '_sort'):
        col['sort'] = model._sort
    if hasattr(model, '_modal'):
        col['modal_size'] = model._modal
    if hasattr(model, '_read_only'):
        col['readOnly'] = model._read_only
    return col

def serialize_schema(schema):
    return [serialize_model(column) for column in schema]
Пример #28
0
    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)
        return name

router = OPALRouter()
Пример #29
0
 def test_import_no_period(self):
     with self.assertRaises(ImportError):
         utils.stringport('wotcha')