from lbrc_flask.database import db from lbrc_flask.security import User as BaseUser users_studies = db.Table( 'users_studies', db.Column( 'user_id', db.Integer(), db.ForeignKey('user.id'), primary_key=True, ), db.Column( 'study_id', db.Integer(), db.ForeignKey('study.id'), primary_key=True, ), ) class User(BaseUser): __table_args__ = {'extend_existing': True} studies = db.relationship("Study", secondary=users_studies, backref=db.backref("users", lazy="joined")) def __str__(self): return 'user'
import uuid import pathlib import re from flask import current_app from sqlalchemy.orm import backref from werkzeug.utils import secure_filename from lbrc_flask.database import db from lbrc_flask.security import User as BaseUser, AuditMixin from lbrc_flask.forms.dynamic import Field, FieldGroup from lbrc_flask.model import CommonMixin services_owners = db.Table( "services_owners", db.Column("service_id", db.Integer(), db.ForeignKey("service.id")), db.Column("user_id", db.Integer(), db.ForeignKey("user.id")), ) class User(BaseUser): __table_args__ = {'extend_existing': True} owned_services = db.relationship("Service", lazy="joined", secondary=services_owners, backref='owners') @property def service_owner(self): return len(self.owned_services) > 0
is_updating = db.Column(db.Boolean) @property def pubmed_name(self): firstname, *_, lastname = self.name.split() return f'{lastname} {firstname[0]}' academics_publications = db.Table( 'academics_publications', db.Column( 'academic_id', db.Integer(), db.ForeignKey('academic.id'), primary_key=True, ), db.Column( 'publication_id', db.Integer(), db.ForeignKey('publication.id'), primary_key=True, ), ) class Publication(AuditMixin, CommonMixin, db.Model): id = db.Column(db.Integer(), primary_key=True) pm_id = db.Column(db.Integer()) journal = db.Column(db.String(200)) published_date = db.Column(db.Date)
def get_type(type_name): return ParticipantIdentifierType.query.filter_by( name=type_name, ).one_or_none() @staticmethod def get_study_participant_id(): return ParticipantIdentifierType.get_type( ParticipantIdentifierTypeName.STUDY_PARTICIPANT_ID) participant_identifiers__participant_identifier_sources = db.Table( 'participant_identifiers__participant_identifier_sources', db.Column('participant_identifier_source_id', db.Integer(), db.ForeignKey('participant_identifier_source.id'), primary_key=True), db.Column('participant_identifier_id', db.Integer(), db.ForeignKey('participant_identifier.id'), primary_key=True), ) class ParticipantIdentifier(db.Model): __tablename__ = 'participant_identifier' id = db.Column(db.Integer, primary_key=True) identifier = db.Column(db.String(100), nullable=False) participant_identifier_type_id = db.Column( db.Integer, db.ForeignKey(ParticipantIdentifierType.id)) participant_identifier_type = db.relationship(ParticipantIdentifierType)
number_portion = "" if self.number: number_portion = " ({})".format(self.number) return self.name + number_portion class User(BaseUser): __table_args__ = {'extend_existing': True} site_id = db.Column(db.Integer, db.ForeignKey(Site.id)) site = db.relationship(Site) studies_owners = db.Table( "studies_owners", db.Column("study_id", db.Integer(), db.ForeignKey("study.id")), db.Column("user_id", db.Integer(), db.ForeignKey("user.id")), ) studies_collaborators = db.Table( "studies_collaborators", db.Column("study_id", db.Integer(), db.ForeignKey("study.id")), db.Column("user_id", db.Integer(), db.ForeignKey(User.id)), ) class Study(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100)) date_created = db.Column(db.DateTime,