class DescriptionBasedModel(BaseModel): __abstract__ = True name = Column("nombre", String(200), nullable=False) description = Column("descripcion", String(600), nullable=False) @classmethod def get_all(cls): return cls.query.all()
class ClinicalStoryModel(TimeBasedModel): __tablename__ = "historias_clinicas" user_id = Column("usuarios_id", Integer, ForeignKey('usuarios.id')) pacient_id = Column("pacientes_id", Integer, ForeignKey('pacientes.id')) edad_paciente = Column(Integer, nullable=False) description = Column("motivo_consulta", String(225), nullable=False) sistolic = Column("sistolica", Integer) diastolic = Column("diastolica", Integer) pulse = Column("pulso", Integer) frec_resp = Column("freq_respiratoria", Integer) temp = Column("temp", Integer) height = Column("estatura", Integer) weight = Column("peso", Integer) diagnosis = Column("diagnostico", String(400)) fisical_exam = Column("examen_fisico", String(4000)) observations = Column("observaciones", String(400)) disponible = Column(Boolean) def update(self, new_values) -> None: for key, value in new_values.items(): setattr(self, key, value) session.commit() def delete_from_db(self): setattr(self, activo, False) @classmethod def find_by_user_id(cls, user_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(user_id=user_id).all() @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all() @classmethod def get_list(cls, query_params) -> "ClinicalStoryModel": query = cls.query if "sistolic" in query_params: query = query.filter_by(sistolic=query_params["sistolic"]) if "diastolic" in query_params: query = query.filter_by(diastolic=query_params["diastolic"]) if "pulse" in query_params: query = query.filter_by(pulse=query_params["pulse"]) if "resp_freq" in query_params: query = query.filter_by(resp_freq=query_params["resp_freq"]) if "temp" in query_params: query = query.filter_by(temp=query_params["temp"]) return query.all()
class MedicineTypeModel(BaseModel): __tablename__ = "medicamentos" nombre = Column(String(600), nullable=False) principio_activo = Column(String(40), nullable=False) laboratorio = Column(String(40), nullable=False) presentacion = Column(String(40)) @classmethod def get_all(cls): return cls.query.all()
class MessageModel(TimeBasedModel): __tablename__ = "mensajes" chat_id = Column("conversaciones_id", Integer, ForeignKey("conversaciones.id")) user_id = Column("usuarios_id", Integer, ForeignKey("conversaciones.id")) content = Column("contenido", String(500), nullable=False) seen = Column("leido", Boolean) date = Column("fecha", DateTime)
class NewsModel(TimeBasedModel): __tablename__ = "noticias" title = Column("titulo", String(100), nullable=False) abstract = Column("resumen", String(500), nullable=False) link = Column("enlace", String(200), nullable=False) img_url = Column(String(200)) @classmethod def get_list(cls, query_params=None) -> "ExamTypeModel": query = cls.query return query.all() def update(self, new_values) -> None: for key, value in new_values.items(): setattr(self, key, value) session.commit()
class Recipes(Base): __tablename__ = 'recipes' id = Column(Integer, primary_key=True) name = Column(String(50)) user_id = Column(ForeignKey('user.id')) def save(self): session.add(self) session.commit()
class FamilyBackgroundModel(BaseModel): __tablename__ = "antecedentes_familiares" family_background_type_id = Column("antecedentes_id", Integer, ForeignKey('antecedentes.id')) pacient_id = Column("pacientes_id", Integer, ForeignKey('pacientes.id')) family_member = Column("familiar", String(40)) @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all()
class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) name = Column(String(50)) password = Column(String(50)) def save(self): session.add(self) session.commit() @classmethod def find_by_id(cls, id): return session.query(cls).filter(cls.id == 1).first() def delete_user(self): session.delete(self) session.commit() def __repr__(self): return f'{self.__dict__}'
class StateModel(BaseModel): __tablename__ = "estados" country_id = Column("paises_id", Integer, ForeignKey('paises.id')) name = Column("nombre", String(100), nullable=False) def __init__(self, name, country_id): self.name = name self.country_id = country_id @classmethod def get_all(cls): return cls.query.all() @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first()
class MunicipalityModel(BaseModel): __tablename__ = "municipios" state_id = Column("estado_id", Integer, ForeignKey('estados.id')) name = Column("nombre", String(100), nullable=False) def __init__(self, name, state_id): self.name = name self.state_id = state_id @classmethod def get_all(cls): return cls.query.all() @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first()
class DirectionModel(BaseModel): __tablename__ = "direcciones" municipality_id = Column("municipios_id", Integer, ForeignKey('municipios.id')) description = Column("detalle", String(100)) def __init__(self, municipality_id, description): self.municipality_id = municipality_id self.description = description @classmethod def get_all(cls): return cls.query.all() @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first()
class CountryModel(BaseModel): __tablename__ = "paises" country_name = Column("nombre", String(50), unique=True, nullable=False) def __init__(self, country_code, country_name): self.country_code = country_code self.country_name = country_name @classmethod def get_all(cls): return cls.query.all() @classmethod def find_by_code(cls, code: str) -> "CountryModel": return cls.query.filter_by(country_code=code).first() @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first()
class ExamResultModel(BaseModel): __tablename__ = "examenes" exam_type_id = Column("type_exam_id", Integer, ForeignKey(ExamTypeModel.id)) clinical_story_id = Column("entradas_id", Integer, ForeignKey('historias_clinicas.id')) result = Column("resultado", String(200), nullable=False) date = Column(Date, nullable=False) def __init__(self, exam_type_id, clinical_story_id, result, date): self.exam_type_id = exam_type_id self.clinical_story_id = clinical_story_id self.result = result self.date = date @classmethod def find_by_exam_type_id(cls, exam_type_id: str) -> "ExamResultModel": return cls.query.filter_by(exam_type_id=exam_type_id).all() @classmethod def find_by_story_id(cls, story_id: str) -> "ExamResultModel": return cls.query.filter_by(clinical_story_id=story_id).all()
class BD_Subs(Base): __tablename__ = 'BD_Subs' id = Column(Integer, primary_key=True) user_id = Column(Integer) sub_name = Column(String(255))
class PacientModel(TimeBasedModel): __tablename__ = "pacientes" current_direction = Column("direccion_actual", Integer, ForeignKey('direcciones.id')) first_name = Column("nombre", String(12), nullable=False) second_name = Column("segundo_nombre", String(12)) last_name = Column("apellido", String(12), nullable=False) second_last_name = Column("segundo_apellido", String(12)) document = Column("documento", String(16), nullable=False, unique=True) gender = Column("sexo", Enum('m', 'f', 'o'), nullable=False) birth_date = Column("fecha_nacimiento", Date) marital_status = Column("estado_civil", Enum('soltero', 'casado', 'divorciado', 'viudo'), nullable=False) blood_type = Column("tipo_sangre", Enum('A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-', 'DESCONOCIDO'), nullable=False) telephone_1 = Column("telefono", String(20)) telephone_2 = Column("telefono2", String(20)) profession = Column("profesion", String(100)) img_url = Column(String(200)) @classmethod def find_by_document(cls, document: str) -> "PacientModel": return cls.query.filter_by(document=document).first() @classmethod def get_list(cls, query_params) -> "PacientModel": query = cls.query if "first_name" in query_params: query = query.filter_by(first_name=query_params["first_name"]) if "second_name" in query_params: query = query.filter_by(second_name=query_params["second_name"]) if "last_name" in query_params: query = query.filter_by(last_name=query_params["last_name"]) if "second_last_name" in query_params: query = query.filter_by( second_last_name=query_params["second_last_name"]) if "gender" in query_params: query = query.filter_by(gender=query_params["gender"]) if "blood_type" in query_params: query = query.filter_by(blood_type=query_params["blood_type"]) if "marital_status" in query_params: query = query.filter_by( marital_status=query_params["marital_status"]) return query.all() def update(self, new_values) -> None: for key, value in new_values.items(): setattr(self, key, value) session.commit()
class UserModel(TimeBasedModel): __tablename__ = "usuarios" email = Column(String(40), nullable=False, unique=True) password = Column("contrasena", String(80), nullable=False) username = Column(String(20), unique=True) first_name = Column("nombre", String(20), nullable=False) last_name = Column("apellido", String(20), nullable=False) role = Column("rol", Enum('Estudiante', 'Medico', 'Medico Especialista', 'Doctor', 'Investigador', 'Administrador'), nullable=False) document = Column("documento", String(16), nullable=False, unique=True) gender = Column("sexo", Enum('m', 'f', 'o'), nullable=False) img_url = Column(String(200)) active = Column("activo", Boolean, server_default='False') def __init__(self, email, password, username, first_name, last_name, role, document, gender, img_url="N/A"): self.email = email self.password = password self.username = username self.first_name = first_name self.last_name = last_name self.role = role self.document = document self.img_url = img_url self.gender = gender self.active = True def deactivate(self) -> None: self.active = False session.commit() @classmethod def find_by_email(cls, email: str) -> "UserModel": return cls.query.filter_by(email=email).first() @classmethod def find_by_username(cls, username: str) -> "UserModel": return cls.query.filter_by(username=username).first() @classmethod def find_by_document(cls, document: str) -> "UserModel": return cls.query.filter_by(document=document).first() @classmethod def get_list(cls, query_params) -> "UserModel": query = cls.query if "first_name" in query_params: print("aca ando") query = query.filter_by(first_name=query_params["first_name"]) if "last_name" in query_params: query = query.filter_by(last_name=query_params["last_name"]) if "gender" in query_params: query = query.filter_by(gender=query_params["gender"]) if "role" in query_params: query = query.filter_by(role=query_params["role"]) if "title" in query_params: query = query.filter_by(title=query_params["title"]) if "college_number" in query_params: query = query.filter_by( college_number=query_params["college_number"]) return query.all() def update(self, new_values) -> None: for key, value in new_values.items(): setattr(self, key, value) session.commit()
class BD_Users(Base): __tablename__ = 'BD_Users' user_id = Column(Integer, primary_key=True) user_name = Column(String(255)) time_start = Column(DateTime()) time_last = Column(DateTime())