Ejemplo n.º 1
0
 def save(self):
     db = DBStorage()
     p = Patient()
     p.name = self.firstName.data
     p.last_name = self.lastname.data
     p.email = self.email.data
     p.phone = self.phone_no.data
     db.add_patient(p)
Ejemplo n.º 2
0
 def save(self):
     """function to save the info getting from wtforms"""
     db = DBStorage()
     p = Patient()
     p.name = self.firstName.data
     p.last_name = self.lastname.data
     p.email = self.email.data
     p.phone = self.phone_no.data
     db.add_patient(p)
Ejemplo n.º 3
0
 def getPatients(self):
     """function to get the existent patients from the db"""
     if not self.patients.choices:
         db = DBStorage()
         options = []
         for patient in db.all_patients():
             options.append((patient.id, '{} {}'.format(
                 patient.name, patient.last_name)))
         self.patients.choices = options
         self.patients.default = 1
Ejemplo n.º 4
0
 def getPatients(self):
     if not self.patients.choices:
         db = DBStorage()
         options = []
         for patient in db.all_patients():
             options.append(
                 (patient.id, '{} {}'.format(patient.name,
                                             patient.last_name)))
         self.patients.choices = options
         self.patients.default = 1
Ejemplo n.º 5
0
    def createCron(self):
        """function that create the crons in the operative
        system to all the task with new status"""
        db = DBStorage()
        cron = CronTab()
        os_user = getpass.getuser()

        for task in db.all_new_tasks():
            args = task.task_command.split()
            date = datetime.strptime('{} {}'.format(args[3], args[4]),
                                     '%Y-%m-%d %H:%M:%S')
            if date <= datetime.now():
                path = os.getcwd()
                cron = CronTab(user=os_user)
                cron_command = '{} {} {} {} {}'.format(
                    args[0], '{}/{}'.format(path, args[1]), args[2], args[3],
                    args[4])
                job = cron.new(command=cron_command,
                               comment="medr-{}".format(task.id))
                if Decimal(args[2]) == 1:
                    job.minute.every(59)
                elif Decimal(args[2]) >= 1:
                    job.hour.every(args[2])
                elif Decimal(args[2]) >= 0 and Decimal(args[2]) < 1:
                    minutes = args[2].split('.')
                    job.minute.every(minutes[1])
                cron.write()
                db.update_task_status(task.id, "CRTD")
                db.get_session().commit()

        print("The following cron's were created: ")
        for item in cron:
            print(item)
        db.get_session().close()
Ejemplo n.º 6
0
 def prescriptionsWithoutTasks(self):
     """ verify every prescription without task
     if there is not a task it is created and the relationship
     if there is a task just the relationship is created """
     db = DBStorage()
     patients = db.all_patients()
     task = []
     for patient in patients:
         if not patient.prescriptions:
             print('there is not prescription for pacient {}'.format(
                 patient.name))
         else:
             for prescription in patient.prescriptions:
                 if not prescription.task_x_prescriptions:
                     task = self.findMyTask(prescription.frequency,
                                            prescription.start_dt)
                     if not task:
                         t = Task()
                         command = 'python3 job.py'
                         command = ' {} {}'.format(command,
                                                   prescription.frequency)
                         command = '{} {}'.format(command,
                                                  prescription.start_dt)
                         t.task_command = command
                         t.task_comment = 'medr-{}'.format(prescription.id)
                         t.last_dt = datetime.now()
                         t.status = 'NEW0'
                         db.add_task(t)
                         print('Task created succesfully')
                         db.add_task_x_prescription(
                             Task_x_prescription(
                                 task_id=t.id,
                                 prescription_id=prescription.id))
                     else:
                         t = task[0]
                         print("""One task match with the frequency {} and
                         the start date {}
                         proceding to set the configuration""".format(
                             prescription.frequency, prescription.start_dt))
                         db.add_task_x_prescription(
                             Task_x_prescription(
                                 task_id=t.id,
                                 prescription_id=prescription.id))
                         print("""The relation between task and
                         prescription was established""")
Ejemplo n.º 7
0
from sqlalchemy.orm import sessionmaker
from backend.models.db_storage import DBStorage
from backend.models.prescription import Prescription
from backend.models.patient import Patient
from datetime import datetime
from twilio.rest import Client
from pathlib import Path
import smtplib
import ssl
import os

account_sid = "Mytwiliosid"
auth_token = "MytwilioToken"
client = Client(account_sid, auth_token)

db = DBStorage()
def sendmail(email, prescription, frequency):
    port = 465
    sender = '*****@*****.**'
    password = '******'
    recieve = email
    message = """
    Subject: medreminder
    Don't forget take your {} every {} hour
    Medreminder
    """.format(prescription, frequency)
    context = ssl.create_default_context()
    with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
        server.login(sender, password)
        server.sendmail(sender, recieve, message)
date = datetime.strptime(
Ejemplo n.º 8
0
 def findMyTask(self, frequency, startDt):
     """find all the task by command in the task table"""
     db = DBStorage()
     task = db.task_by_command('python3 job.py {} {}'.format(
         frequency, startDt))
     return task
Ejemplo n.º 9
0
 def getTasks(self, prescriptionID):
     """function that get the task info from the wtforms"""
     tasks = []
     db = DBStorage()
     tasks = db.taskByPrescriptions(prescriptionID)
     return tasks
Ejemplo n.º 10
0
 def getPrescriptions(self):
     """function that get the prescription info from the wtforms"""
     db = DBStorage()
     prescriptions = db.prescriptionXpatientID(int(self.selectedid))
     return prescriptions
Ejemplo n.º 11
0
 def getPatients(self):
     """function that get the patients info from the wtforms"""
     db = DBStorage()
     self.patients = db.all_patients()
Ejemplo n.º 12
0
 def save(self):
     """function to save a new prescription for a given patient"""
     db = DBStorage()
     p = self.createPatient()
     db.add_prescription(p)
Ejemplo n.º 13
0
 def save(self):
     db = DBStorage()
     p = self.createPatient()
     db.add_prescription(p)
Ejemplo n.º 14
0
#!/usr/bin/python3
"""DataBase Storage"""
from backend.models.db_storage import DBStorage
from backend.models.patient import Base, Patient

x = DBStorage().all_patients()
y = DBStorage().all_prescription()
z = DBStorage().all_task_x_prescription()
zz = DBStorage().all_task()