コード例 #1
0
 def __load_symptoms(cls):
     """ Load accepted symptoms from file. """
     Logger(cls.__name__).info('Loading accepted symptoms...')
     file_name = f'{cls.PATH}{cls.SYMPTOMS}'
     with open(file_name) as fd:
         symptoms = load(fd)
     return symptoms
コード例 #2
0
 def tornado_app():
     """ Create Tornado application. """
     Logger('ApplicationFactory').info('Creating Tornado Application...')
     # Define location of templates and static files
     settings = {
         'template_path':
         abspath(join(dirname(__file__), "../../views/templates")),
         'static_path':
         abspath(join(dirname(__file__), "../../views/static"))
     }
     # Create application by assigning routes and the location of view files
     return Application(Router.routes(), **settings)
コード例 #3
0
 async def __load_family_groups(cls):
     """ Read family groups file and load on database if it was not previously done. """
     if await FamilyGroupDAO.all(): return
     # Only load file if there are no doctors in the database
     Logger(cls.__name__).info(
         'Creating basic family group database entries...')
     file_name = f'{cls.PATH}{cls.INITIAL_RESOURCES_FOLDER}{cls.FAMILY_GROUPS}'
     with open(file_name) as fd:
         families = load(fd)
     # Add every doctor to the database
     for family in families:
         await FamilyGroupDAO.store(family.get('members', list()))
コード例 #4
0
 async def __load_doctors(cls):
     """ Read doctors file and load on database if it was not previously done. """
     if await DoctorDAO.all(): return
     # Only load file if there are no doctors in the database
     Logger(cls.__name__).info('Creating basic doctor database entries...')
     file_name = f'{cls.PATH}{cls.INITIAL_RESOURCES_FOLDER}{cls.DOCTORS}'
     with open(file_name) as fd:
         doctors = load(fd)
     # Add every doctor to the database
     for doctor in doctors:
         await DoctorManagementService.add(
             DoctorManagementRequestMapper.map_creation(doctor))
コード例 #5
0
 def __create_client(cls, etcd_host, etcd_port) -> Client:
     """ Create etcd client and test connection. """
     Logger(cls.__name__).info('Connecting to etcd server...')
     client = Client(host=etcd_host, port=etcd_port)
     # Test connection by trying to read a random value
     try:
         client.read('nodes')
     except EtcdConnectionFailed:
         raise EtcdConnectionError(port=etcd_port)
     except EtcdKeyNotFound:
         # This is to handle the case where etcd did not have the key (we don't care) but it is running
         pass
     return client
コード例 #6
0
def start():
    # Parse command line argument_parsing
    port, processes, db_data, env = ArgumentParsingUtils.parse_arguments()
    # Set up logger
    Logger.set_up()
    # Create Tornado application
    Logger(__name__).info('Setting up application...')
    app = AppCreator.create_app()
    # Start server on given port and with given processes
    ServerCreator.create(app, port).start(processes)
    # Establish database connection for each process
    Mongo.init(**db_data)
    Mongo.create_indexes()
    app.settings['db'] = Mongo.get()
    # Create basic database entries
    ResourceLoader.load_resources(env)
    # Set up rules engine
    SpecialtyResolver.set_up(env)
    PriorityResolver.set_up(env)
    # Start event loop
    Logger(__name__).info(f'Listening on http://localhost:{port}.')
    IOLoop.current().start()
コード例 #7
0
 async def __load_users(cls):
     """ Read users file and load on database if it was not previously done. """
     if await AuthenticationDAO.get_all({}): return
     # Only load file if there are no users in the database
     Logger(cls.__name__).info(
         'Creating basic authentication database entries...')
     file_name = f'{cls.PATH}{cls.INITIAL_RESOURCES_FOLDER}{cls.USERS}'
     with open(file_name) as fd:
         users = load(fd)
     # Add every user to the database
     for user in users:
         await AuthenticationDAO.add(
             AuthData(user_id=user['user_id'],
                      password=user['password'],
                      role=user['role'],
                      device_id=''))
コード例 #8
0
 async def __load_affiliates(cls):
     """ Read affiliates file and load on database if it was not previously done. """
     if await AffiliateDAO.all(): return
     # Only load file if there are no doctors in the database
     Logger(
         cls.__name__).info('Creating basic affiliate database entries...')
     file_name = f'{cls.PATH}{cls.INITIAL_RESOURCES_FOLDER}{cls.AFFILIATES}'
     with open(file_name) as fd:
         affiliates = load(fd)
     # Add every affiliate to the database
     for affiliate in affiliates:
         await AffiliateDAO.store(
             Affiliate(id=affiliate['id'],
                       dni=affiliate['dni'],
                       first_name=affiliate['first_name'],
                       last_name=affiliate['last_name'],
                       plan=affiliate['plan'],
                       sex=affiliate['sex'],
                       age=affiliate['age'],
                       device_id=''))
コード例 #9
0
 def get_logger(cls):
     return Logger(cls.__name__)
コード例 #10
0
 def get_logger(self):
     return Logger(self.__class__.__name__)
コード例 #11
0
 def set_up(cls, env):
     Logger(cls.__name__).info(f'Creating {cls.__name__} rules engine...')
     rules_path = f'{abspath(join(dirname(__file__), "../../.."))}{"/" if env != "docker" else ""}{cls.file_path()}'
     cls.__RULES = RuleLoader.load_rules_from_file(rules_path)