Exemplo n.º 1
0
    def __init__(self, beginning):
        self.today = Tick(beginning)
        self.history = list()
        self.model = self._load_model()
        host = 'sormas' if os.environ.get('DOCKERIZED') else 'localhost'
        configuration = sormas_api.Configuration(
            host=f'http://{host}:6080/sormas-rest',
            username='******',
            password='******')
        configuration.verify_ssl = False
        configuration.debug = True
        self.sormas_api_config = configuration

        self.regions = {}
        self.districts = {}

        with sormas_db_connect() as conn:
            with conn.cursor() as cur:
                cur.execute("SELECT name, uuid FROM region")
                res = cur.fetchone()
                self.regions[res[0]] = res[1]
                cur.execute("SELECT name, uuid FROM district")
                res = cur.fetchone()
                self.districts[res[0]] = res[1]

                # disable other diseases
                cur.execute(
                    "UPDATE diseaseconfiguration SET active = true WHERE disease = 'CORONAVIRUS'"
                )
                cur.execute(
                    "UPDATE diseaseconfiguration SET active = false WHERE disease != 'CORONAVIRUS'"
                )
Exemplo n.º 2
0
def surv_sup_user_ref():
    with sormas_db_connect() as conn:
        with conn.cursor() as cur:
            cur.execute(
                "SELECT uuid FROM users WHERE firstname = 'Surveillance' AND lastname = 'Supervisor'"
            )
            uuid = cur.fetchone()[0]
            return UserReferenceDto(uuid=uuid)
def insert_region(region):
    with sormas_db_connect() as conn:
        with conn.cursor() as cur:
            cur.execute("SELECT uuid FROM region WHERE name=%s", [region])
            exists = cur.fetchone()[0]
            if exists:
                print(f'{region} already exists in the DB')
                return exists
            cur.execute("SELECT id FROM region")
            all_ids = list(chain.from_iterable(cur.fetchall()))
            _id = max(all_ids) + 1
            date = datetime.date.today()
            uuid = duuid()
            cur.execute(
                "INSERT INTO region (id,changedate, creationdate, name, uuid, epidcode, archived)"
                "VALUES (%s,%s, %s, %s, %s, %s, %s)",
                [_id, date, date, region, uuid, 'REG', False])
            return uuid
Exemplo n.º 4
0
def insert_district(district, region_id):
    with sormas_db_connect() as conn:
        with conn.cursor() as cur:
            cur.execute("SELECT uuid FROM district WHERE name=%s", [district])
            exists = cur.fetchone()[0]
            if exists:
                logging.info(f'{district} already exists in the DB')
                return exists

            cur.execute("SELECT id FROM district")
            all_ids = list(chain.from_iterable(cur.fetchall()))
            _id = max(all_ids) + 1
            date = datetime.date.today()
            uuid = duuid()
            cur.execute(
                "INSERT INTO district (id, changedate, creationdate, name, uuid, region_id, epidcode, archived)"
                "VALUES (%s,%s, %s, %s, %s, %s, %s, %s)",
                [_id, date, date, district, uuid, region_id, 'DIS', False])

            return uuid
Exemplo n.º 5
0
    def __init__(self, beginning):
        self.today = Tick(beginning)
        self.history = None
        self.model = self._load_model()
        sormas_domain = os.environ.get("DOMAIN_NAME")
        logging.info(f'SORMAS domain: {sormas_domain}')
        host = sormas_domain if sormas_domain else 'localhost'

        configuration = sormas_api.Configuration(
            host=f'http://{host}:6080/sormas-rest',
            username='******',
            password='******'
        )

        configuration.verify_ssl = False
        configuration.debug = True
        self.sormas_api_config = configuration

        self.regions = {}
        self.districts = {}

        with sormas_db_connect() as conn:
            with conn.cursor() as cur:
                cur.execute("SELECT name, id, uuid FROM region")
                res = cur.fetchone()
                logging.info(f'Region: {res}')
                self.regions[res[0]] = {}
                self.regions[res[0]]['id'] = res[1]
                self.regions[res[0]]['uuid'] = res[2]
                cur.execute("SELECT name, id, uuid FROM district")
                res = cur.fetchone()
                self.districts[res[0]] = {}
                self.districts[res[0]]['id'] = res[1]
                self.districts[res[0]]['uuid'] = res[2]
                logging.info(f'District: {res}')

                # disable other diseases
                cur.execute("UPDATE diseaseconfiguration SET active = true WHERE disease = 'CORONAVIRUS'")
                cur.execute("UPDATE diseaseconfiguration SET active = false WHERE disease != 'CORONAVIRUS'")
Exemplo n.º 6
0
def default_district():
    with sormas_db_connect() as conn:
        with conn.cursor() as cur:
            cur.execute("SELECT uuid FROM district")
            uuid = cur.fetchone()[0]
            return DistrictReferenceDto(uuid=uuid)
def default_region():
    with sormas_db_connect() as conn:
        with conn.cursor() as cur:
            cur.execute("SELECT uuid FROM region")
            uuid = cur.fetchone()[0]
            return RegionReferenceDto(uuid=uuid)