class IndicatorTypeModel(db.Model, BaseMethods):
    __tablename__ = 'indicators_type'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    unitOfMeasureId = db.Column(db.Integer,
                                db.ForeignKey('units_of_measure.id',
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                                nullable=False)
    unitOfMeasure = db.relationship('UnitOfMeasureModel')
    indicators = db.relationship('IndicatorModel', lazy='dynamic')

    name = db.Column(db.String(100))
    shortName = db.Column(db.String(3))

    def __init__(self, unit_of_measure_id, name, short_name):
        super(IndicatorTypeModel, self).__init__()
        self.unitOfMeasureId = unit_of_measure_id
        self.name = name
        self.shortName = short_name

    def __repr__(self):
        return 'Role: %r' % self.name

    def json(self):
        return {
            'id': self.id,
            'unitOfMeasure': self.unitOfMeasure.json(),
            'name': self.name,
            'shortName': self.shortName
        }
Esempio n. 2
0
class PlanModel(db.Model, BaseMethods):
    __tablename__ = 'plans'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    patients = db.relationship('PatientModel', lazy='dynamic')
    doctors = db.relationship('DoctorModel', lazy='dynamic')

    name = db.Column(db.String(50))
    shortName = db.Column(db.String(3))
    description = db.Column(db.String(150))
    acceptedPatients = db.Column(db.Integer)
    price = db.Column(db.Numeric(9, 3))

    def __init__(self, name, short_name, description, accepted_patients, price):
        super(PlanModel, self).__init__()
        self.name = name
        self.shortName = short_name
        self.description = description
        self.acceptedPatients = accepted_patients
        self.price = price

    def __repr__(self):
        return 'Plan: %r' % self.name

    def json(self):
        return {
            'id': self.id,
            'name': self.name,
            'shortName': self.shortName,
            'description': self.description,
            'acceptedPatients': self.acceptedPatients,
            'price': float(self.price)
        }
class MedicalSpecialityModel(db.Model, BaseMethods):
    __tablename__ = 'medical_specialities'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    doctorSpecialities = db.relationship('DoctorSpecialityModel', lazy='dynamic')

    name = db.Column(db.String(70))
    shortName = db.Column(db.String(3))

    def __init__(self, name, short_name):
        super(MedicalSpecialityModel, self).__init__()
        self.name = name
        self.shortName = short_name

    def __repr__(self):
        return 'Medical Speciality: %r' % self.name

    def json(self):
        return {
            'id': self.id,
            'name': self.name,
            'shortName': self.shortName
        }
class Roles(db.Model):
    """
    Roles permissions
    """
    role_id = db.Column(db.Integer, primary_key=True)
    role = db.Column(db.String(10))
    user_id = db.relationship('UserMixin', backref='roles')
class IndicatorEntryModel(db.Model, BaseMethods):
    __tablename__ = 'indicators_entry'

    id = db.Column(db.Integer, primary_key=True)

    # Relationship
    indicatorId = db.Column(db.Integer, db.ForeignKey('indicators.id', onupdate='CASCADE',
                                                      ondelete='CASCADE'), nullable=False)
    indicator = db.relationship('IndicatorModel')

    value = db.Column(db.String(20))
    createdAt = db.Column(db.DateTime, nullable=False)

    def __init__(self, indicator_id, value, created_at):
        super(IndicatorEntryModel, self).__init__()
        self.indicatorId = indicator_id
        self.value = value
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (created_at is None) else created_at

    def __repr__(self):
        return 'Indicator Entry: %r' % self.value

    def json(self):
        return {
            'id': self.id,
            'indicator': self.indicator.json(),
            'value': self.value
        }
Esempio n. 6
0
class DoctorSpecialityModel(db.Model, BaseMethods):
    __tablename__ = 'doctor_specialities'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    doctorId = db.Column(db.Integer,
                         db.ForeignKey('doctors.id',
                                       onupdate='CASCADE',
                                       ondelete='CASCADE'),
                         nullable=False)
    doctor = db.relationship('DoctorModel')
    medicalSpecialityId = db.Column(db.Integer,
                                    db.ForeignKey('medical_specialities.id',
                                                  onupdate='CASCADE',
                                                  ondelete='CASCADE'),
                                    nullable=False)
    medicalSpeciality = db.relationship('MedicalSpecialityModel')

    def __init__(self, doctor_id, medical_speciality_id):
        super(DoctorSpecialityModel, self).__init__()
        self.doctorId = doctor_id
        self.medicalSpecialityId = medical_speciality_id

    def __repr__(self):
        return 'Doctor Speciality: %r' % self.doctorId

    def json(self, only_spec=bool):
        if only_spec:
            return {
                'id': self.id,
                'medicalSpeciality': self.medicalSpeciality.json()
            }
        else:
            return {
                'id': self.id,
                'doctor': self.doctor.json(),
                'medicalSpeciality': self.medicalSpeciality.json()
            }

    @classmethod
    def verify_doctor_speciality(cls, doctor_id, med_speciality):
        return cls.query.filter_by(doctorId=doctor_id).filter_by(
            medicalSpecialityId=med_speciality).first()
class IndicatorModel(db.Model, BaseMethods):
    __tablename__ = 'indicators'

    id = db.Column(db.Integer, primary_key=True)

    # Relationship
    patientId = db.Column(db.Integer, db.ForeignKey('patients.id', onupdate='CASCADE',
                                                    ondelete='CASCADE'), nullable=False)
    patient = db.relationship('PatientModel')
    indicatorTypeId = db.Column(db.Integer, db.ForeignKey('indicators_type.id', onupdate='CASCADE',
                                                          ondelete='CASCADE'), nullable=False)
    indicatorType = db.relationship('IndicatorTypeModel')
    indicatorsEntry = db.relationship('IndicatorEntryModel', lazy='dynamic')

    quantity = db.Column(db.Numeric(9, 3))
    frequency = db.Column(db.String(200))
    createdAt = db.Column(db.DateTime, nullable=False)

    def __init__(self, patient_id, indicator_typ_id, quantity, frequency, created_at):
        super(IndicatorModel, self).__init__()
        self.patientId = patient_id
        self.indicatorTypeId = indicator_typ_id
        self.quantity = quantity
        self.frequency = frequency
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (created_at is None) else created_at

    def __repr__(self):
        return 'Indicator %r' % self.frequency

    def json(self):
        return {
            'id': self.id,
            'patient': self.patient.json(),
            'indicatorType': self.indicatorType.json(),
            'quantity': self.quantity,
            'frequency': self.frequency
        }
Esempio n. 8
0
class RoleModel(db.Model, BaseMethods):
    __tablename__ = 'roles'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    users = db.relationship('UserModel', lazy='dynamic')

    name = db.Column(db.String(60), nullable=False)
    shortName = db.Column(db.String(3), nullable=False)

    def __init__(self, name, short_name):
        super(RoleModel, self).__init__()
        self.name = name
        self.shortName = short_name

    def __repr__(self):
        return 'Role: %r' % self.name

    def json(self):
        return {'id': self.id, 'name': self.name, 'shortName': self.shortName}
class DistrictModel(db.Model, BaseMethods):
    __tablename__ = 'districts'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    addresses = db.relationship('AddressModel', lazy='dynamic')

    name = db.Column(db.String(100), nullable=False)
    shortName = db.Column(db.String(3), nullable=False)

    def __init__(self, name, short_name):
        super(DistrictModel, self).__init__()
        self.name = name
        self.shortName = short_name

    def __repr__(self):
        return 'District: %r' % self.name

    def json(self):
        return {'id': self.id, 'name': self.name, 'shortName': self.shortName}
Esempio n. 10
0
class UnitOfMeasureModel(db.Model, BaseMethods):
    __tablename__ = 'units_of_measure'

    id = db.Column(db.Integer, primary_key=True)

    # Relationship
    indicators_type = db.relationship('IndicatorTypeModel', lazy='dynamic')

    name = db.Column(db.String(60), nullable=False)
    shortName = db.Column(db.String(3), nullable=False)

    def __init__(self, name, short_name):
        super(UnitOfMeasureModel, self).__init__()
        self.name = name
        self.shortName = short_name

    def __repr__(self):
        return 'Unit of Measure: %r' % self.name

    def json(self):
        return {'id': self.id, 'name': self.name, 'shortName': self.shortName}
Esempio n. 11
0
class DeviceModel(db.Model, BaseMethods):
    __tablename__ = 'devices'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    userId = db.Column(db.Integer,
                       db.ForeignKey('users.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    user = db.relationship('UserModel')

    ip = db.Column(db.String(15), nullable=False)
    createdAt = db.Column(db.DateTime, nullable=False)

    def __init__(self, user_id, ip, created_at):
        super(DeviceModel, self).__init__()
        self.userId = user_id
        self.ip = ip
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            created_at is None) else created_at

    def __repr__(self):
        return 'Device: %r' % self.token

    def json(self):
        return {
            'id': self.id,
            'user': self.user.json(is_long=False),
            'ip': self.ip
        }

    @classmethod
    def find_by_ip(cls, ip):
        return cls.query.filter_by(ip=ip).first()
class AppointmentModel(db.Model, BaseMethods):
    __tablename__ = 'appointments'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    doctorId = db.Column(db.Integer, db.ForeignKey('doctors.id', onupdate='CASCADE', ondelete='CASCADE')
                         , nullable=False)
    doctor = db.relationship('DoctorModel')
    patientId = db.Column(db.Integer, db.ForeignKey('patients.id', onupdate='CASCADE', ondelete='CASCADE')
                          , nullable=False)
    patient = db.relationship('PatientModel')

    appointmentDate = db.Column(db.DateTime, nullable=False)
    reason = db.Column(db.String(200))
    createdAt = db.Column(db.DateTime, nullable=False)
    canceledAt = db.Column(db.DateTime)
    updatedOn = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, doctor_id, patient_id, appointment_date, reason, created_at, canceled_at, updated_on, status):
        super(AppointmentModel, self).__init__()
        self.doctorId = doctor_id
        self.patientId = patient_id
        self.appointmentDate = (datetime.now() + timedelta(hours=2)) if (appointment_date is None) else appointment_date
        self.reason = reason
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (created_at is None) else created_at
        self.canceledAt = canceled_at
        self.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (updated_on is None) else updated_on
        self.status = status

    def __repr__(self):
        return 'Appointment: %r' % self.reason

    def json(self, role_id):
        if role_id == 1:
            return {
                'id': self.id,
                'patient': self.patient.json(),
                'appointmentDate': self.appointmentDate,
                'reason': self.reason,
                'canceledAt': self.canceledAt,
                'status': self.status
            }
        else:
            return {
                'id': self.id,
                'doctor': self.doctor.json(),
                'appointmentDate': self.appointmentDate,
                'reason': self.reason,
                'canceledAt': self.canceledAt,
                'status': self.status
            }

    @classmethod
    def find_by_patient_id(cls, patient_id):
        return cls.query.filter_by(patientId=patient_id).all()

    @classmethod
    def find_by_doctor_id(cls, doctor_id):
        return cls.query.filter_by(doctorId=doctor_id).all()

    @classmethod
    def find_by_appointment_date(cls, appointment_date):
        return cls.query.filter_by(appointmentDate=appointment_date).first()
class MembershipModel(db.Model, BaseMethods):
    __tablename__ = 'memberships'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    doctorId = db.Column(db.Integer, db.ForeignKey('doctors.id', onupdate='CASCADE',
                                                   ondelete='CASCADE'), nullable=False)
    doctor = db.relationship('DoctorModel')
    patientId = db.Column(db.Integer, db.ForeignKey('patients.id', onupdate='CASCADE',
                                                    ondelete='CASCADE'), nullable=False)
    patient = db.relationship('PatientModel')

    referencedEmail = db.Column(db.String(45), nullable=False)
    accessCode = db.Column(db.String(6))
    createdAt = db.Column(db.DateTime, nullable=False)
    expiresAt = db.Column(db.DateTime)
    updatedOn = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, doctor_id, patient_id, referenced_email, access_code, created_at, expires_at, updated_on, status):
        super(MembershipModel, self).__init__()
        self.doctorId = doctor_id
        self.patientId = patient_id
        self.referencedEmail = referenced_email
        self.accessCode = access_code
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (created_at is None) else created_at
        self.expiresAt = (datetime.now() + timedelta(hours=24)).strftime('%Y-%m-%d %H:%M:%S') if (expires_at is None) \
            else expires_at
        self.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (updated_on is None) else updated_on
        self.status = status

    def __repr__(self):
        return 'Membership: %r' % self.referencedEmail

    def json(self, role_id):
        if role_id == 1:
            return {
                'id': self.id,
                'patient': self.patient.json(),
                'referencedEmail': self.referencedEmail,
                'accessCode': self.accessCode,
                'expiredAt': self.expiresAt,
                'status': self.status
            }
        else:
            return {
                'id': self.id,
                'doctor': self.doctor.json(),
                'referencedEmail': self.referencedEmail,
                'accessCode': self.accessCode,
                'expiredAt': self.expiresAt,
                'status': self.status
            }

    @classmethod
    def find_by_patient_id(cls, patient_id):
        return cls.query.filter_by(patientId=patient_id).first()

    @classmethod
    def find_by_doctor_id(cls, doctor_id):
        return cls.query.filter_by(doctorId=doctor_id).first()
Esempio n. 14
0
class AddressModel(db.Model, BaseMethods):
    __tablename__ = 'addresses'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    districtId = db.Column(db.Integer,
                           db.ForeignKey('districts.id',
                                         onupdate='CASCADE',
                                         ondelete='CASCADE'),
                           nullable=False)
    district = db.relationship('DistrictModel')
    doctors = db.relationship('DoctorModel', lazy='dynamic')

    street = db.Column(db.String(100))
    neighborhood = db.Column(db.String(100))
    complement = db.Column(db.String(100))
    number = db.Column(db.String(5))
    createdAt = db.Column(db.DateTime, nullable=False)
    updatedOn = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, district_id, street, neighborhood, complement, number,
                 created_at, updated_on, status):
        super(AddressModel, self).__init__()
        self.districtId = district_id
        self.street = street
        self.neighborhood = neighborhood
        self.complement = complement
        self.number = number
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            created_at is None) else created_at
        self.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            updated_on is None) else updated_on
        self.status = status

    def __repr__(self):
        return 'Address: %r' % self.street

    def json(self, doctors_list=bool):
        if doctors_list:
            return {
                'doctors': list(map(lambda x: x.json(), self.doctors)),
                'district': self.district.json(),
                'street': self.street,
                'neighborhood': self.neighborhood,
                'complement': self.complement,
                'number': self.number
            }
        else:
            return {
                'district': self.district.json(),
                'street': self.street,
                'neighborhood': self.neighborhood,
                'complement': self.complement,
                'number': self.number
            }

    @classmethod
    def find_by_number(cls, number):
        return cls.query.filter_by(number=number).first()
Esempio n. 15
0
class PatientModel(db.Model, BaseMethods):
    __tablename__ = 'patients'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    userId = db.Column(db.Integer,
                       db.ForeignKey('users.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    user = db.relationship('UserModel')
    planId = db.Column(db.Integer,
                       db.ForeignKey('plans.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    plan = db.relationship('PlanModel')
    appointments = db.relationship('AppointmentModel', lazy='dynamic')
    memberships = db.relationship('MembershipModel', lazy='dynamic')
    prescriptions = db.relationship('PrescriptionModel', lazy='dynamic')
    indicators = db.relationship('IndicatorModel', lazy='dynamic')

    age = db.Column(db.Integer, nullable=False)
    bloodType = db.Column(db.String(3))
    weight = db.Column(db.Numeric(9, 3))
    sex = db.Column(db.String(10))
    height = db.Column(db.Numeric(9, 3))
    createdAt = db.Column(db.DateTime, nullable=False)
    updatedOn = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, user_id, plan_id, age, blood_type, weight, sex, height,
                 created_at, updated_on, status):
        super(PatientModel, self).__init__()
        self.userId = user_id
        self.planId = plan_id
        self.age = age
        self.bloodType = blood_type
        self.weight = weight
        self.sex = sex
        self.height = height
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            created_at is None) else created_at
        self.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            updated_on is None) else updated_on
        self.status = status

    def __repr__(self):
        return 'Patient: %r' % self.age

    def json(self):
        return {
            'id': self.id,
            'user': self.user.json(is_long=True),
            'plan': self.plan.json(),
            'age': self.age,
            'bloodType': self.bloodType,
            'weight': float(self.weight),
            'sex': self.sex,
            'height': float(self.height),
            'status': self.status
        }

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.query.filter_by(userId=user_id).first()
Esempio n. 16
0
class DoctorModel(db.Model, BaseMethods):
    __tablename__ = 'doctors'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    userId = db.Column(db.Integer,
                       db.ForeignKey('users.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    user = db.relationship('UserModel')
    planId = db.Column(db.Integer,
                       db.ForeignKey('plans.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    plan = db.relationship('PlanModel')
    addressId = db.Column(
        db.Integer,
        db.ForeignKey('addresses.id', onupdate='CASCADE', ondelete='CASCADE'))
    address = db.relationship('AddressModel')
    doctorSpecialities = db.relationship('DoctorSpecialityModel',
                                         lazy='dynamic')
    appointments = db.relationship('AppointmentModel', lazy='dynamic')
    memberships = db.relationship('MembershipModel', lazy='dynamic')
    prescriptions = db.relationship('PrescriptionModel', lazy='dynamic')

    doctorIdentification = db.Column(db.String(20), nullable=False)
    createdAt = db.Column(db.DateTime, nullable=False)
    updatedOn = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, user_id, plan_id, address_id, doctor_identification,
                 created_at, updated_on, status):
        super(DoctorModel, self).__init__()
        self.userId = user_id
        self.planId = plan_id
        self.addressId = address_id
        self.doctorIdentification = doctor_identification
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            created_at is None) else created_at
        self.updatedOn = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            updated_on is None) else updated_on
        self.status = status

    def __repr__(self):
        return 'Doctor: %r' % self.doctorIdentification

    def json(self):
        return {
            'id':
            self.id,
            'user':
            self.user.json(is_long=True),
            'plan':
            self.plan.json(),
            'address':
            self.address.json(doctors_list=False) if
            (self.addressId is not None) else None,
            'doctorIdentification':
            self.doctorIdentification,
            'status':
            self.status
        }

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.query.filter_by(userId=user_id).first()
class PrescriptionModel(db.Model, BaseMethods):
    __tablename__ = 'prescriptions'

    id = db.Column(db.Integer, primary_key=True)

    # Relationships
    doctorId = db.Column(db.Integer,
                         db.ForeignKey('doctors.id',
                                       onupdate='CASCADE',
                                       ondelete='CASCADE'),
                         nullable=False)
    doctor = db.relationship('DoctorModel')
    patientId = db.Column(db.Integer,
                          db.ForeignKey('patients.id',
                                        onupdate='CASCADE',
                                        ondelete='CASCADE'),
                          nullable=False)
    patient = db.relationship('PatientModel')
    prescriptionTypeId = db.Column(db.Integer,
                                   db.ForeignKey('prescriptions_type.id',
                                                 onupdate='CASCADE',
                                                 ondelete='CASCADE'),
                                   nullable=False)
    prescriptionType = db.relationship('PrescriptionTypeModel')

    frequency = db.Column(db.String(50))
    quantity = db.Column(db.Integer)
    durationInDays = db.Column(db.Integer)
    description = db.Column(db.String(250))
    createdAt = db.Column(db.DateTime, nullable=False)
    startedAt = db.Column(db.DateTime)
    finishedAt = db.Column(db.DateTime)
    status = db.Column(db.String(3), server_default='ACT')

    def __init__(self, doctor_id, patient_id, prescription_type_id, frequency,
                 quantity, duration_in_days, description, created_at,
                 started_at, finished_at, status):
        super(PrescriptionModel, self).__init__()
        self.doctorId = doctor_id
        self.patientId = patient_id
        self.prescriptionTypeId = prescription_type_id
        self.frequency = frequency
        self.quantity = quantity
        self.durationInDays = duration_in_days
        self.description = description
        self.createdAt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if (
            created_at is None) else created_at
        self.startedAt = started_at
        self.finishedAt = (datetime.strptime(started_at, '%Y-%m-%d %H:%M:%S') + timedelta(days=duration_in_days))\
            .strftime('%Y-%m-%d %H:%M:%S') if (finished_at is None) else finished_at
        self.status = status

    def __repr__(self):
        return 'Prescription: %r' % self.description

    def json(self, role_id):
        if role_id == 1:
            return {
                'id': self.id,
                'patient': self.patient.json(),
                'prescriptionType': self.prescriptionType.json(),
                'frequency': self.frequency,
                'quantity': self.quantity,
                'durationInDays': self.durationInDays,
                'description': self.description,
                'startedAt': self.startedAt,
                'finishedAt': self.finishedAt,
                'status': self.status
            }
        else:
            return {
                'id': self.id,
                'doctor': self.doctor.json(),
                'prescriptionType': self.prescriptionType.json(),
                'frequency': self.frequency,
                'quantity': self.quantity,
                'durationInDays': self.durationInDays,
                'description': self.description,
                'startedAt': self.startedAt,
                'finishedAt': self.finishedAt,
                'status': self.status
            }

    @classmethod
    def find_by_doctor_and_patient_id(cls, doctor_id, patient_id):
        return cls.query.filter_by(doctorId=doctor_id).filter_by(
            patientId=patient_id).all()