示例#1
0
class Location(db.Model):
    __tablename__ = 'locations'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    location_coord = db.Column(db.String())  #Coordinates
    district = db.Column(db.String(300), nullable=False)
    state = db.Column(db.String(300))
    country = db.Column(db.String(300))
示例#2
0
class algorithms(db.Model):
    __tablename__='algorithms'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    AlgorithmName=db.Column(db.String(100),nullable=False)
    AlgorithmLoc = db.Column(db.String(1000),nullable=False)
    DefaultAlgorithm = db.Column(db.Boolean,nullable=False, default=False)
    Accuracy = db.Column(db.String(20))
示例#3
0
class PHCUser(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String)
    username = db.Column(db.String)
    location = db.Column(db.Integer,
                         ForeignKey('locations.id'),
                         nullable=False)
    password = db.Column(db.String(100))
    permission = db.Column(db.String(10), default='User')
示例#4
0
class outbreak_analysis(db.Model):
    __tablename__='outbreak_analysis'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    EntryTime = db.Column(db.DateTime)
    CentreCode = db.Column(db.Integer)
    Disease = db.Column(db.String(200))
    OutbreakFlag = db.Column(db.Integer)
示例#5
0
class medicaldata(db.Model):
    __tablename__='medicaldata'
    id=db.Column(db.Integer, primary_key=True, autoincrement=True)
    EntryTime=db.Column(db.DateTime)
    CentreCode=db.Column(db.Integer,nullable=False)
    Disease=db.Column(db.String(300),nullable=False)
    Age=db.Column(db.Integer)
    NoOfCases=db.Column(db.Integer, default=1, nullable=False)
示例#6
0
 def status(cls):
     return db.Column(db.String(20), index=True, default="INSERT")
示例#7
0
class BaseModelCommonFields(db.Model):
    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True)

    ins_username = db.Column(db.String(30))
    ins_address = db.Column(db.String(50))
    ins_timestamp = db.Column(db.DateTime,
                              default=datetime.datetime.now,
                              index=True)

    upd_username = db.Column(db.String(30))
    upd_address = db.Column(db.String(50))
    upd_timestamp = db.Column(db.DateTime,
                              default=datetime.datetime.now,
                              index=True)

    __table_args__ = (  #db.Index('ix_otp_expire_otp', 'otp_expire', 'otp'),
    )

    def __repr__(self):
        return "<BaseCommonFields {}>".format(self.id)

    def detach(self):
        return make_transient(self)

    def as_dict(self, show=None, hide=None, recurse=None):
        """ Return a dictionary representation of this model.
		"""

        obj_d = {
            'id':
            self.id,
            'ins_username':
            self.ins_username,
            'ins_address':
            self.ins_address,
            'ins_timestamp':
            self.ins_timestamp.isoformat() if self.ins_timestamp else None,
            'upd_username':
            self.upd_username,
            'upd_address':
            self.upd_address,
            'upd_timestamp':
            self.upd_timestamp.isoformat() if self.upd_timestamp else None,
        }

        return obj_d

    def log_user(self, username, address=""):
        address = address or ""

        if not self.ins_username:
            self.ins_username = username

        if not self.ins_address:
            self.ins_address = address

        self.upd_username = username
        self.upd_address = address

        self.log_timestamp()

        return self

    def log_timestamp(self):
        if self.upd_timestamp:
            self.upd_timestamp = datetime.datetime.now()

        return self

    def set_user(self, req, user):

        return self.log_user(user.username, req.remote_addr)

    #omnisearch methods
    __search_fields__ = ("id", )

    @classmethod
    def omnisearch(cls, txt):
        """
			Search every field defined in __search_fields__ who got 'txt' inside.
			Returns query object with such elements
		"""
        txt_like = "%{}%".format(txt)

        args = [getattr(cls, f).like(txt_like) for f in cls.__search_fields__]

        return cls.query.filter(db.or_(*args))

    @property
    def is_omnisearched(self, txt):

        txt_lower = txt.lower()

        return any(txt_lower in getattr(cls, f).lower()
                   for f in self.__search_fields__)

    @classmethod
    def add_new(cls, *args, **kwargs):
        kw = kwargs.copy()
        db_session = kw.pop("db_session", None) or db.session

        item = cls(*args, **kw)

        db_session.add(item)

        return item

    @classmethod
    def find_or_create(cls, *args, **kwargs):

        kw = kwargs.copy()
        db_session = kw.pop("db_session", None)
        add_new = kw.pop("add_new", None)

        item = cls.query.filter_by(*args, **kw).first()

        if not item:
            if add_new or db_session:
                kw["db_session"] = db_session
                return cls.add_new(*args, **kw)
            else:
                item = cls(*args, **kwargs)

        return item

    @property
    def serialized_id(self):
        return "{}:{}".format(self.__class__.__name__, self.id)

    @classmethod
    def get_from_serialized(cls, serial_id):
        (cls_name, cls_id) = serial_id.split(":")[:2]

        if cls_name != cls.__name__:
            raise Exception("MODEL INTEGRITY ERROR: Serial id not valid")

        return cls.query.get(cls_id)
示例#8
0
class AdminModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String)
    username = db.Column(db.String)
    password = db.Column(db.String(100))
    permission = db.Column(db.String(10), default='Admin')
示例#9
0
class reports(db.Model):
    __tablename__='reports'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    ReportTime=db.Column(db.DateTime,nullable=False)
    ReportLoc=db.Column(db.String(1000),nullable=False)
    Algorithm=db.Column(db.String(300))
示例#10
0
class Diseases(db.Model):
    __tablename__ = 'diseases'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    Disease = db.Column(db.String(300), nullable=False)