-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
98 lines (69 loc) · 2.78 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Drug(db.Model):
"""a drug"""
__tablename__ = 'drugs'
drug_id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
pk_id = db.Column(db.Integer, db.ForeignKey('pks.pk_id'))
pgx_id = db.Column(db.Integer, db.ForeignKey('pgx.pgx_id'))
dosage_id = db.Column(db.Integer, db.ForeignKey('dosage.dosage_id'))
dosage = db.relationship("Dosage", backref="drug")
pharmacokinetics = db.relationship("Pharmacokinetics", backref="drug")
pharmacogenomics = db.relationship("Pharmacogenomics", backref="drugs")
generic_name = db.Column(db.String)
brand_name = db.Column(db.String)
pharmGKB_ID = db.Column(db.String)
pgx_moa = db.Column(db.String)
def __repr__(self):
return f'<drug_id={self.drug_id} generic={self.generic_name} brand={self.brand_name}>'
class Dosage(db.Model):
"""dosing for a drug"""
__tablename__ = "dosage"
dosage_id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
dosing = db.Column(db.Text)
special_populations = db.Column(db.Text)
pgx = db.Column(db.Text)
def __repr__(self):
return f'<dosing_id={self.dosage_id} dosing ={self.dosing}>'
class Pharmacokinetics(db.Model):
"""PK of a drug"""
__tablename__ = 'pks'
pk_id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
overview = db.Column(db.Text)
absorption = db.Column(db.Text)
distribution = db.Column(db.Text)
elimination = db.Column(db.Text)
special_populations = db.Column(db.Text)
ddi_studies = db.Column(db.Text)
def __repr__(self):
return f'<pk id ={self.pk_id} drug ={self.overview}>'
class Pharmacogenomics(db.Model):
"""PGx of a drug"""
__tablename__ = "pgx"
pgx_id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
overview = db.Column(db.Text)
dosage = db.Column(db.Text)
special_populations = db.Column(db.Text)
ddis = db.Column(db.Text)
lab_tests = db.Column(db.Text)
precautions = db.Column(db.Text)
def __repr__(self):
return f'<pgx id ={self.pgx_id} drug ={self.overview}>'
def connect_to_db(flask_app, db_uri='postgresql:///drugs', echo=False):
flask_app.config['SQLALCHEMY_DATABASE_URI'] = db_uri
flask_app.config['SQLALCHEMY_ECHO'] = echo
flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.app = flask_app
db.init_app(flask_app)
print('Connected to the db!')
if __name__ == '__main__':
from server import app
connect_to_db(app)