class SampleValue(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    substance_id = db.Column(db.Integer,
                             db.ForeignKey('substance.id'),
                             default=0)
    sample_id = db.Column(db.Integer, db.ForeignKey('sample.id'), default=0)
    well_id = db.Column(db.Integer, db.ForeignKey('well.id'), default=0)
    upload_id = db.Column(db.Integer, db.ForeignKey('upload.id'), default=None)
    value = db.Column(db.Float(12), default=0.0)
    free_product = db.Column(db.Boolean, default=False)
    non_detect = db.Column(db.Boolean, default=False)
    less_than = db.Column(
        db.Float(12), default=0.0)  # Save less than values for the sticklers
    details = db.Column(db.String(20), default=None)
    new = db.Column(db.Boolean, default=True)
    paid_level_1 = db.Column(db.Boolean, default=False)
    paid_level_2 = db.Column(db.Boolean, default=False)
    sample = db.relationship('Sample',
                             backref=db.backref('values',
                                                lazy='dynamic',
                                                cascade='all'))
    substance = db.relationship('Substance', lazy='joined')
    well = db.relationship('Well',
                           backref=db.backref('sample_values',
                                              lazy='dynamic',
                                              cascade='all'))

    def __repr__(self):
        return '<SampleValue {}>'.format(self.id)
Beispiel #2
0
class Office(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    contact = db.Column(db.String(255), default=None)
    address = db.Column(db.String(80))
    city = db.Column(db.String(255))
    state = db.Column(db.String(2))
    zip = db.Column(db.String(32))
    phone = db.Column(db.String(32), default=None)
    cell = db.Column(db.String(32), default=None)
    email = db.Column(db.String(255), default=None)
    lat = db.Column(db.Float(10))
    lng = db.Column(db.Float(10))

    def __repr__(self):
        return '<Office {} ({})>'.format(self.title, self.id)
Beispiel #3
0
class SiteMap(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    site_id = db.Column(db.Integer, db.ForeignKey('site.id'))
    title = db.Column(db.String(255))
    width = db.Column(db.Integer)
    height = db.Column(db.Integer)
    url = db.Column(db.String(255))
    scale = db.Column(db.Float(12), default=1.0)
    site = db.relationship('Site',
                           backref=db.backref('sitemaps',
                                              lazy='dynamic',
                                              cascade='all'))

    def __repr__(self):
        return '<SiteMap {} ({})>'.format(self.title, self.id)

    def json(self):
        res = dict()

        for field in self._fields():
            res[field] = getattr(self, field)

        res['wells'] = []

        for well in self.wells:
            res['wells'].append(well.json())

        return res
Beispiel #4
0
class Substance(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    substance_group_id = db.Column(db.Integer,
                                   db.ForeignKey('substance_group.id'),
                                   nullable=False,
                                   default=0)
    active = db.Column(db.Boolean, default=False, index=True)
    hard_ref = db.Column(db.Integer, default=0)
    title = db.Column(db.String(255), index=True)
    abbreviation = db.Column(db.String(255))
    cas = db.Column(db.String(255))
    cas_sanitized = db.Column(db.String(255), index=True)
    sort = db.Column(db.Integer, default=0)
    unit = db.Column(db.String(16))
    precision = db.Column(db.Integer, default=2)
    criteria = db.Column(db.Float(12), default=0.0)
    field_data = db.Column(db.Boolean, default=False)

    @validates('cas')
    def update_slug(self, key, cas):
        if cas and len(cas):
            self.cas_sanitized = cas.replace('-', '').replace(' ', '').upper()
            return cas

    def __repr__(self):
        return '<Substance {} ({})>'.format(self.title, self.id)
Beispiel #5
0
class Transaction(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    lab_id = db.Column(db.Integer, db.ForeignKey('lab.id'))
    site_id = db.Column('site_id', db.Integer, db.ForeignKey('site.id'))
    company_id = db.Column('company_id', db.Integer, db.ForeignKey('company.id'))
    created_at = db.Column(db.DateTime, default=db.func.now())
    total_amount = db.Column(db.Float(12))
    lab_earnings_amount = db.Column(db.Float(12))
    samples = db.Column(JSON)
    stripe_transaction_id = db.Column(db.String(255))
    stripe_card_id = db.Column(db.String(255))
    cc_last4 = db.Column(db.Integer)
    user = db.relationship('User', backref=db.backref('transactions', lazy='dynamic'))

    def __repr__(self):
        return '<Transaction {} ({})>'.format(self.total_amount, self.id)
class Well(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    site_id = db.Column(db.Integer, db.ForeignKey('site.id'))
    frequency_id = db.Column(db.Integer)
    active = db.Column(db.Boolean, default=True)
    title = db.Column(db.String(255), default='', index=True)
    top_of_casing = db.Column(db.Float(10), default=0.0)
    xpos = db.Column(db.Integer, default=0)
    ypos = db.Column(db.Integer, default=0)
    xpos_fields = db.Column(db.Integer, default=0)
    ypos_fields = db.Column(db.Integer, default=0)
    sort = db.Column(db.Integer, default=0)
    sampletechnique = db.Column(db.String(255), default='')
    material = db.Column(db.String(255))
    diameter = db.Column(db.Float(9))
    screenlength = db.Column(db.Float(9))
    est_depth_to_water = db.Column(db.Float(10))
    depth_to_bottom = db.Column(db.Float(9))
    purge_water_disposal = db.Column(db.String(255))
    latitude = db.Column(db.Float(9))
    longitude = db.Column(db.Float(9))
    notes = db.Column(db.Text)

    def __repr__(self):
        return '<Well {} ({})>'.format(self.title, self.id)
Beispiel #7
0
class CriteriaValues(BaseModel):
    __tablename__ = "criteria_values"
    id = db.Column(db.Integer, primary_key=True)
    criteria_id = db.Column(db.Integer,
                            db.ForeignKey('criteria.id'),
                            nullable=False)
    substance_id = db.Column(db.Integer,
                             db.ForeignKey('substance.id'),
                             nullable=False)
    value = db.Column(db.Float(12), nullable=False)
class Site(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    state_id = db.Column(db.Integer, db.ForeignKey('state.id'))
    company_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    additional_owner_ids = db.Column(JSON)
    consultant_id = db.Column(db.Integer)
    additional_consultant_ids = db.Column(JSON)
    sampler_id = db.Column(db.Integer)
    lab_id = db.Column(db.Integer, db.ForeignKey('lab.id'))
    manager_id = db.Column(db.Integer)
    created_at = db.Column(db.DateTime, default=db.func.now())
    active = db.Column(db.Boolean, default=True)
    title = db.Column(db.String(255), index=True)
    sort = db.Column(db.Integer, default=0)
    facility_id = db.Column(db.String(255))
    contact = db.Column(db.String(255))
    contact_phone = db.Column(db.String(255))
    contact_email = db.Column(db.String(255))
    notes = db.Column(db.Text)
    address = db.Column(db.String(255))
    city = db.Column(db.String(128))
    state = db.Column(db.String(64))
    zip = db.Column(db.String(32))
    county = db.Column(db.String(64))
    latitude = db.Column(db.Float(9), default=0)
    longitude = db.Column(db.Float(9), default=0)
    start_sampling_on = db.Column(db.DateTime)
    history = db.Column(db.Text)
    background = db.Column(db.Text)
    summary = db.Column(db.Text)
    qaqc_duplicates = db.Column(db.Boolean, default=False)
    qaqc_duplicates_per_samples = db.Column(db.Integer, default=0)
    qaqc_duplicates_type = db.Column(db.String(16))
    qaqc_duplicates_well_ids = db.Column(JSON)
    qaqc_duplicates_test_ids = db.Column(JSON)
    qaqc_msmsds = db.Column(db.Boolean, default=False)
    qaqc_msmsds_per_samples = db.Column(db.Integer, default=0)
    qaqc_msmsds_type = db.Column(db.String(16))
    qaqc_msmsds_well_ids = db.Column(JSON)
    qaqc_msmsds_test_ids = db.Column(JSON)
    qaqc_fieldblanks = db.Column(db.Boolean, default=False)
    qaqc_fieldblanks_per_samples = db.Column(db.Integer, default=0)
    qaqc_fieldblanks_type = db.Column(db.String(16))
    qaqc_fieldblanks_test_ids = db.Column(JSON)
    qaqc_tripblanks = db.Column(db.Boolean, default=False)
    qaqc_tripblanks_per_samples = db.Column(db.Integer, default=0)
    qaqc_tripblanks_type = db.Column(db.String(16))
    qaqc_tripblanks_test_ids = db.Column(JSON)
    qaqc_equipmentblanks = db.Column(db.Boolean, default=False)
    qaqc_equipmentblanks_per_samples = db.Column(db.Integer, default=0)
    qaqc_equipmentblanks_type = db.Column(db.String(16))
    qaqc_equipmentblanks_test_ids = db.Column(JSON)
    client_id = db.Column(db.Integer, db.ForeignKey('client.id'))
    lab = db.relationship('Lab', backref=db.backref('sites', lazy='dynamic', cascade='all'))
    client = db.relationship('Client', backref=db.backref('sites', lazy='dynamic', cascade='all'))
    wells = db.relationship('Well', backref='sites', lazy='dynamic', cascade='all')
    substances = db.relationship('Substance', secondary=substances_sites, lazy='dynamic', backref=db.backref('sites', lazy='dynamic'))
    data = db.relationship('SiteData', backref=db.backref('sites', lazy='joined', cascade='all'))

    def __repr__(self):
        return '<Site {} ({})>'.format(self.title, self.id)

    @hybrid_property
    def role_query(self):
        if g.current_role == 'Admin':
            return self.query.filter_by(lab_id=g.current_lab.id)
        elif g.current_role == 'LabAdmin' or g.current_role == 'LabAssociate':
            return self.query.filter_by(lab_id=g.current_lab.id)
        elif g.current_role == 'CompanyAdmin' or g.current_role == 'CompanyAssociate':
            return self.query \
                .join(self.client) \
                .join(Client.company) \
                .join(Company.users) \
                .filter(self.lab == g.current_lab) \
                .filter(User.id == current_user.id)
        elif g.current_role == 'ClientManager':
            return self.query \
                .join(self.client) \
                .join(Client.users) \
                .filter(self.lab == g.current_lab) \
                .filter(User.id == current_user.id)
        elif g.current_role == 'Technician':
            return self.query \
                .join(self.users) \
                .filter(self.lab == g.current_lab) \
                .filter(User.id == current_user.id)

        return self.query.filter(False)

    def json(self):
        res = dict()

        for field in self._fields():
            res[field] = getattr(self, field)

        res['user_ids'] = []

        for user in self.users:
            res['user_ids'].append(user.id)

        # Append wells
        res['well_ids'] = []

        for well in self.wells:
            res['well_ids'].append(well.id)

        # Append substances
        res['substance_ids'] = []

        for substance in self.substances:
            res['substance_ids'].append(substance.id)

        return res