Ejemplo n.º 1
0
    server_stored_var_table_defunct,
    ServerSettings,
    ServerStoredVarNamesDefunct,
)
from camcops_server.cc_modules.cc_sqlalchemy import Base
from camcops_server.cc_modules.cc_taskindex import reindex_everything
from camcops_server.cc_modules.cc_user import (
    SecurityAccountLockout,
    SecurityLoginFailure,
    User,
)

if TYPE_CHECKING:
    from sqlalchemy.engine.result import ResultProxy

log = BraceStyleAdapter(logging.getLogger(__name__))

DEBUG_VIA_PDB = False

# =============================================================================
# Information relating to the source database
# =============================================================================


def get_skip_tables(src_tables: List[str]) -> List[TableIdentity]:
    """
    From the list of source table names provided, return details of tables in
    the metadata to skip because they are not in the source database.

    Also checks that some core CamCOPS tables are present in the source, or
    raises :exc:`ValueError`.
Ejemplo n.º 2
0
)

from camcops_server.cc_modules.cc_baseconstants import (
    LINUX_DEFAULT_CAMCOPS_CONFIG_DIR,
    LINUX_DEFAULT_CAMCOPS_DIR,
    LINUX_DEFAULT_LOCK_DIR,
    LINUX_DEFAULT_MATPLOTLIB_CACHE_DIR,
)
from camcops_server.cc_modules.cc_pythonversion import (
    assert_minimum_python_version, )
from camcops_server.cc_modules.cc_version_string import (
    CAMCOPS_SERVER_VERSION_STRING,
    CAMCOPS_SERVER_CHANGEDATE,
)

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# Python version requirements
# =============================================================================

assert_minimum_python_version()

# =============================================================================
# URL defaults and other constants
# =============================================================================

PACKAGE_DEB_NAME = "camcops-server"  # no underscores for Debian
PACKAGE_DIR_NAME = "camcops_server"
ETC_DIR_NAME = "camcops"
CAMCOPS_EXECUTABLE = "camcops_server"
Ejemplo n.º 3
0
    SessionTokenColType,
)
from camcops_server.cc_modules.cc_sqlalchemy import Base
from camcops_server.cc_modules.cc_taskfilter import TaskFilter
from camcops_server.cc_modules.cc_unittest import DemoDatabaseTestCase
from camcops_server.cc_modules.cc_user import (
    SecurityAccountLockout,
    SecurityLoginFailure,
    User,
)

if TYPE_CHECKING:
    from camcops_server.cc_modules.cc_request import CamcopsRequest
    from camcops_server.cc_modules.cc_tabletsession import TabletSession

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# Debugging options
# =============================================================================

DEBUG_CAMCOPS_SESSION_CREATION = False

if DEBUG_CAMCOPS_SESSION_CREATION:
    log.warning("Debugging options enabled!")

# =============================================================================
# Constants
# =============================================================================

DEFAULT_NUMBER_OF_TASKS_TO_VIEW = 25
Ejemplo n.º 4
0
import datetime
import logging
import sys
from typing import Any, Dict, List
import unittest

from numpy import array
from pandas import DataFrame

from cardinal_pythonlib.interval import Interval, IntervalList
from cardinal_pythonlib.logs import (
    BraceStyleAdapter,
    main_only_quicksetup_rootlogger,
)

log = BraceStyleAdapter(logging.getLogger(__name__))

DEFAULT_PATIENT_COLNAME = "patient_id"
DEFAULT_DRUG_EVENT_DATETIME_COLNAME = "drug_event_datetime"
DEFAULT_START_DATETIME_COLNAME = "start"
DEFAULT_QUERY_DATETIME_COLNAME = "when"


def drug_timelines(
        drug_events_df: DataFrame,
        event_lasts_for: datetime.timedelta,
        patient_colname: str = DEFAULT_PATIENT_COLNAME,
        event_datetime_colname: str = DEFAULT_DRUG_EVENT_DATETIME_COLNAME) \
        -> Dict[Any, IntervalList]:
    """
    Takes a set of drug event start times (one or more per patient), plus a
Ejemplo n.º 5
0
"""  # noqa

# =============================================================================
# Basic imports
# =============================================================================

import atexit
import logging
import os
import shutil
import tempfile

from cardinal_pythonlib.logs import BraceStyleAdapter

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# Constants
# =============================================================================

ENVVAR_HOME = "HOME"
ENVVAR_MPLCONFIGDIR = "MPLCONFIGDIR"

# =============================================================================
# Import matplotlib
# =============================================================================

# We need to use os.environ, since per-request stuff won't be initialized yet.
# That goes for anything that affects imports (to avoid the complexity of
# delayed imports).
Ejemplo n.º 6
0
)
from cardinal_pythonlib.reprfunc import auto_repr
from cardinal_pythonlib.sqlalchemy.orm_inspect import get_orm_column_names
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy.sql.schema import Column
from sqlalchemy.sql.sqltypes import Integer

from camcops_server.cc_modules.cc_sqla_coltypes import (
    CamcopsColumn,
    PermittedValueChecker,
    permitted_value_failure_msgs,
    permitted_values_ok,
)
from camcops_server.cc_modules.cc_sqlalchemy import Base

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# 1. Explore the metaclass system in detail
# =============================================================================

MODIFY_CLASS = True

if __name__ == "__main__":
    # Before classes are even declared:
    main_only_quicksetup_rootlogger()
    log.info("Module starting to load.")


def add_multiple_fields(
    cls: Type,
Ejemplo n.º 7
0
Importing this module does the following:

- ensure that all models are loaded;
- provide log message around some of the slow imports.

"""

# SET UP LOGGING BEFORE WE IMPORT CAMCOPS MODULES, allowing them to log during
# imports (see e.g. cc_plot).
# Currently sets up colour logging even if under WSGI environment. This is fine
# for gunicorn from the command line; I'm less clear about whether the disk
# logs look polluted by ANSI codes; needs checking.
import logging
from cardinal_pythonlib.logs import BraceStyleAdapter

log = BraceStyleAdapter(logging.getLogger(__name__))
log.info("Imports starting")

# Main imports

import os  # nopep8
import platform  # nopep8
import subprocess  # nopep8
import tempfile  # nopep8
from typing import Any, Dict, List, Optional, TYPE_CHECKING  # nopep8
import unittest  # nopep8

import cherrypy  # nopep8
try:
    from gunicorn.app.base import BaseApplication
except ImportError:
Ejemplo n.º 8
0
    XML_COMMENT_CALCULATED,
    XmlElement,
)

if TYPE_CHECKING:
    from camcops_server.cc_modules.cc_blob import Blob  # noqa: F401
    from camcops_server.cc_modules.cc_patient import Patient  # noqa: F401
    from camcops_server.cc_modules.cc_request import (
        CamcopsRequest,  # noqa: F401
    )
    from camcops_server.cc_modules.cc_summaryelement import (
        SummaryElement,  # noqa: F401
    )
    from camcops_server.cc_modules.cc_task import Task  # noqa: F401

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# Hacks for specific database drivers
# =============================================================================

CRASH_ON_BAD_CONVERSIONS = False  # for debugging only!

if CRASH_ON_BAD_CONVERSIONS:
    log.error("DANGER: CRASH_ON_BAD_CONVERSIONS set in cc_db.py")

try:
    import MySQLdb
    import MySQLdb.converters
except ImportError:
    MySQLdb = None