app.models package¶
Submodules¶
app.models.forms module¶
Forms for registering doctors, patients, and prescriptions.
-
class
app.models.forms.
InfoForm
(*args, **kwargs)[source]¶ Bases:
flask_wtf.form.FlaskForm
Base class for registering names and email.
-
class
app.models.forms.
LoginForm
(*args, **kwargs)[source]¶ Bases:
app.models.forms.UserForm
Final class for logging in existing users (doctors).
-
class
app.models.forms.
PatientForm
(*args, **kwargs)[source]¶ Bases:
app.models.forms.InfoForm
Final class for registering new patients.
-
class
app.models.forms.
PrescriptionForm
(*args, **kwargs)[source]¶ Bases:
flask_wtf.form.FlaskForm
Form for creating new prescriptions.
-
class
app.models.forms.
RegistrationForm
(*args, **kwargs)[source]¶ Bases:
app.models.forms.InfoForm
,app.models.forms.UserForm
Final class for registering new users (doctors).
app.models.medication module¶
-
class
app.models.medication.
Intake
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
Intake model. Intakes are created when the app receives a recording, indicating that a patient has taken medication.
-
class
app.models.medication.
Prescription
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
Prescription model.
drug = name of drug desc = purpose/description of drug/prescription (aka “indication”) strength = how much of the drug per tablet (e.g. 30mg) strength_unit = unit for strength (e.g. mg, ug) quantity = number of tablets per fill cycle form = form factor of pill (for now, only tablet aka ‘tab’) amount = number of units taken per intake route = how it gets into the body (only oral for now) freq = how many times per freq_repeat_unit freq_repeat = every <freq_repeat> <freq_repeat_unit> freq_repeat_unit = how often a day of intake repeats (e.g. every 3 days) duration = length of entire treatment refills = number of expected refills throughout duration time_of_day = time pill(s) should be taken (e.g. AM, PM)
created = date this Prescription was created; auto-filled start_date = start date of first intake (regardless of refill) last_refill_date = date of most recent refill next_refill = date of next refill; auto-filled field days_until_refill = days until next refill; auto-filled field
patient_id = patient ID for which this Prescription is for intakes = collection of Intakes for this Prescription (one to many field)
-
days_until_refill
()[source]¶ Return number of days until next refill. If curr_date > next_refill_date, for instance, if refill was not fulfilled
in time, then days until refill is still 0.
-
frac_on_time
(date=datetime.datetime(2020, 6, 18, 9, 6, 24, 706605))[source]¶ Return fraction of intakes that were on time, out of all recorded intakes. date: datetime - get fraction on time intakes on or before this date
-
frac_required_intakes
(date=datetime.datetime(2020, 6, 18, 9, 6, 24, 706606))[source]¶ Return fraction of recorded intakes, out of total number of intakes that are supposed to be recorded by this time. date: datetime - get fraction on track intakes on or before this date
-
generate_schedule
()[source]¶ Generates the schedule which is a list of rx’s, where each rx is a list of dictionaries with key being the date and value being another dictionary of metadata.
Currently only works for the case when freq_repeat = 1 and freq_repeat_unit = day
-
app.models.persons module¶
Classes to model users (doctors) and patients.
-
class
app.models.persons.
BasicInfo
[source]¶ Bases:
object
Base class for modeling users and patients.
-
class
app.models.persons.
Patient
(firstname, lastname, email, age, weight, user=None)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
,app.models.persons.BasicInfo
Defines a Patient, which has a foreign key pointed to User (doctor).
-
adherence_stats
(date=datetime.datetime(2020, 6, 18, 9, 6, 24, 717736))[source]¶ Return adherence statistics on a per-Prescription basis. return: dict - <prescription ID>: <details> Example: {
- 1: {
‘frac_on_time’: 0.932, ‘frac_required_intakes’: 0.976
}, 19: {
‘frac_on_time’: 0.389, ‘frac_required_intakes’: 1.0
}
-
all_intakes
(start=None, end=None)[source]¶ Return Intake objects associated with this Patient. start: datetime - optional start date for filtering end: datetime - optional end date for filtering
TODO: Implement start, end filtering NOTE: There’s probably a better way of doing this. Perhaps setting Patient
as a foreign key in Intake?
-
frac_adhering_prescriptions
(on_time_threshold=0.9, required_intakes_threshold=0.9)[source]¶ Return fraction of prescriptions for this Patient that are deemed adherent. Adherence requires Intakes to be recorded on time and on track (i.e. medications aren’t missed).
on_time_threshold: float - fraction on time Intakes needed for this prescription to be deemed adherent required_intakes_threshold: float - fraction Intakes actually recorded, out of all prescribed Intakes since start date.
-
is_adherent
(on_time_threshold=0.9, required_intakes_threshold=0.9, date=datetime.datetime(2020, 6, 18, 9, 6, 24, 717742))[source]¶ Whether or not a patient is deemed adherent based on their prescription adherence.
on_time_threshold: float - fraction on time Intakes needed for this prescription to be deemed adherent required_intakes_threshold: float - fraction Intakes actually recorded, out of all prescribed Intakes since start date.
-
-
class
app.models.persons.
User
(firstname, lastname, username, email, password)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
,flask_login.mixins.UserMixin
,app.models.persons.BasicInfo
User model with functions to set and check password when logging in.