コード例 #1
0
class Bed(db.Model):
    __tablename__ = 'beds'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    bed_name = db.Column(db.String(60), nullable=False)
    bed_desc = db.Column(db.String(120))
    bed_loc = db.Column(
        db.String(60))  # refer to a place (room, level, or building)
    bed_pic = db.Column(db.String(60))  # refer to staff/person/etc.
    bed_status = db.Column(
        db.Boolean)  # refer to (used, unused, etc.) need to list more
    production_date = db.Column(db.DateTime)
    is_used = db.Column(db.Boolean)
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    bed_history = db.relationship('BedHistory',
                                  backref='history_bed',
                                  lazy='dynamic')
    bed_safety = db.relationship('BedSafety',
                                 backref='safety_bed',
                                 lazy='dynamic')
    bed_security = db.relationship('BedSecurity',
                                   backref='security_bed',
                                   lazy='dynamic')
    bed_productivity = db.relationship('BedProductivity',
                                       backref='productivity_bed',
                                       lazy='dynamic')

    def __repr__(self):
        return '<Bed {}>'.format(self.bed_name)
コード例 #2
0
class Room(db.Model):
    __tablename__ = 'rooms'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    room_name = db.Column(db.String(60), nullable=False)
    room_pic = db.Column(db.String(60)) # refer to staff/person/etc.
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    level_id = db.Column(db.Integer, db.ForeignKey('levels.id'))
    rooms_history = db.relationship('RoomHistory',
                                     backref='history_room',
                                     lazy='dynamic')
    rooms_safety = db.relationship('RoomSafety',
                                    backref='safety_room',
                                    lazy='dynamic')
    rooms_security = db.relationship('RoomSecurity',
                                      backref='security_room',
                                      lazy='dynamic')
    rooms_productivity = db.relationship('RoomProductivity',
                                          backref='productivity_room',
                                          lazy='dynamic')

    def __repr__(self):
        return '<Room {}>'.format(self.room_name)
コード例 #3
0
class MedicalDevice(db.Model):
    __tablename__ = 'medical_devices'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    device_name = db.Column(db.String(60), nullable=False)
    device_desc = db.Column(db.String(120))
    device_loc = db.Column(
        db.String(60))  # refer to a place (room, level, or building)
    device_pic = db.Column(db.String(60))  # refer to staff/person/etc.
    device_status = db.Column(
        db.Boolean)  # refer to (used, unused, etc.) need to list more
    production_date = db.Column(db.DateTime)
    is_on = db.Column(db.Boolean)
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    device_type_id = db.Column(db.Integer,
                               db.ForeignKey('medical_devices_type.id'))
    device_history = db.relationship('MedicalDeviceHistory',
                                     backref='history_device',
                                     lazy='dynamic')
    device_safety = db.relationship('MedicalDeviceSafety',
                                    backref='safety_device',
                                    lazy='dynamic')
    device_security = db.relationship('MedicalDeviceSecurity',
                                      backref='security_device',
                                      lazy='dynamic')
    device_productivity = db.relationship('MedicalDeviceProductivity',
                                          backref='productivity_device',
                                          lazy='dynamic')

    def __repr__(self):
        return '<Device {}>'.format(self.device_name)
コード例 #4
0
class State(db.Model):
    __tablename__ = 'states'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    state_name = db.Column(db.String(60), nullable=False)
    count_hospitals = db.Column(db.Integer)
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    roles = db.relationship('Role', backref='role_state', lazy='dynamic')
    hospitals = db.relationship('Hospital', backref='hospital_state', lazy='dynamic')
    states_history = db.relationship('StateHistory', backref='history_state', lazy='dynamic')

    def __repr__(self):
        return '<State: {}>'.format(self.state_name)
コード例 #5
0
class Room(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)
    room_name = db.Column(db.Text, nullable=False)
    encoded_room_name = db.Column(db.Text, nullable=False)
    date_created = db.Column(db.DateTime, default=func.now(), nullable=False)
    private = db.Column(db.Boolean, default=False)
    password = db.Column(db.Text)
    items = db.relationship('Item', cascade='all, delete-orphan')


    def __init__(self, room_name):
        self.room_name = room_name
        self.encoded_room_name = self.encode_room(room_name)

    def encode_room(self, room_name):
        rooms_with_same_name = Room.query.filter_by(room_name=room_name)
        if rooms_with_same_name.count() >= 1:
            room_name = "".join([room_name, str(rooms_with_same_name.count())])
        hashed_room_name = hashlib.md5(room_name.encode()).digest()
        room_encoding = base64.urlsafe_b64encode(hashed_room_name).decode()
        return room_encoding.strip('=')

    def get_items(self):
        d = {}
        for i in self.__table__.columns:
            if i.name in ['encoded_room_name', 'password']:
                continue
            else:
                d[i.name] = getattr(self, i.name)
        d['items'] = [j.get_info() for j in self.items]
        return d
コード例 #6
0
class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)
    associated_room = db.Column(
        db.Integer,
        db.ForeignKey('room.id',ondelete='CASCADE')
    )
    name = db.Column(db.Text, nullable=False)
    description = db.Column(db.Text)
    who_owns = db.Column(db.Text, nullable=False)
    who_has_current = db.Column(db.Text)
    how_long_can_borrow = db.Column(db.Text)
    due_back = db.Column(db.DateTime)
    date_posted = db.Column(db.DateTime, default=func.now(), nullable=False)
    active = db.Column(db.Boolean, default=True)
    history = db.relationship('BorrowHistory', cascade='all, delete-orphan')

    def __init__(self, room, name, who_owns):
        self.associated_room = room.id
        self.name = name
        self.who_owns = who_owns

    def get_info(self):
        d = {}
        for i in self.__table__.columns:
            d[i.name] = getattr(self, i.name)

        d['history'] = [j.get_history_info() for j in self.history]
        return d
コード例 #7
0
class MedicalDeviceType(db.Model):
    __tablename__ = 'medical_devices_type'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(120))
    type_desc = db.Column(db.String(240))
    devices = db.relationship('MedicalDevice',
                              backref='device_type',
                              lazy='dynamic')
コード例 #8
0
class Level(db.Model):
    __tablename__ = 'levels'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    level_name = db.Column(db.String(60), nullable=False)
    level_pic = db.Column(db.String(60),
                          nullable=True)  # refer to staff/person/etc.
    count_rooms = db.Column(db.Integer)
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    building_id = db.Column(db.Integer, db.ForeignKey('buildings.id'))
    rooms = db.relationship('Room', backref='room_level', lazy='dynamic')
    levels_history = db.relationship('LevelHistory',
                                     backref='history_level',
                                     lazy='dynamic')

    def __repr__(self):
        return '<Level {}>'.format(self.level_name)
コード例 #9
0
class Role(db.Model):
    __tablename__ = 'roles'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    scope = db.Column(db.String(60), nullable=False)
    state_id = db.Column(db.Integer, db.ForeignKey('states.id'))
    hospital_id = db.Column(db.Integer, db.ForeignKey('hospitals.id'))
    users = db.relationship('User', backref='user_role', lazy='dynamic')

    def __repr__(self):
        return '<Role: {}>'.format(self.scope)
コード例 #10
0
class Hospital(db.Model):
    __tablename__ = 'hospitals'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    hospital_name = db.Column(db.String(60), nullable=False)
    count_buildings = db.Column(db.Integer)
    count_rooms = db.Column(db.Integer)
    current_safety = db.Column(db.Integer)
    current_security = db.Column(db.Integer)
    current_productivity = db.Column(db.Integer)
    state_id = db.Column(db.Integer, db.ForeignKey('states.id'))
    roles = db.relationship('Role', backref='role_hospital', lazy='dynamic')
    buildings = db.relationship('Building',
                                backref='building_hospital',
                                lazy='dynamic')
    hospitals_history = db.relationship('HospitalHistory',
                                        backref='history_hospital',
                                        lazy='dynamic')

    def __repr__(self):
        return '<Hospital {}>'.format(self.hospital_name)