Пример #1
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}
Пример #2
0
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
        }
Пример #3
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()