class ChatModel(BaseModel): __tablename__ = "conversaciones" user_id = Column("usuarios_id", Integer, ForeignKey("usuarios.id")) user2_id = Column("usuarios2_id", Integer, ForeignKey("usuarios.id")) @classmethod def find_by_users(cls, user, user2): chat = cls.query.filter_by(user_id=user).filter_by( user2_id=user2).first() if not chat: chat = cls.query.filter_by(user_id=user2).filter_by( user2_id=user).first() return chat @classmethod def find_by_single_user(cls, user_id): chatsUser1 = cls.query.filter_by(user_id=user_id).all() chatUser2 = cls.query.filter_by(user2_id=user_id).all() chat_mix = chatsUser1 for chat in chatUser2: if chat_mix.count(chat) == 0: chat_mix.append(chat) return chat_mix
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 SymptomModel(BaseModel): __tablename__ = "sintomas" symptom_type_id = Column("tipo_sintomas_id", Integer, ForeignKey(SymptomTypeModel.id)) clinical_story_id = Column("historias_clinicas_id", Integer, ForeignKey('historias_clinicas.id')) @classmethod def find_by_story_id(cls, story_id: str) -> "ExamResultModel": return cls.query.filter_by(clinical_story_id=story_id).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 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 AllergyModel(BaseModel): __tablename__ = "alergias" allergy_type_id = Column(Integer, ForeignKey('tipo_alergias.id')) pacient_id = Column(Integer, ForeignKey('pacientes.id')) def __init__(self, allergy_type_id, pacient_id): self.allergy_type_id = allergy_type_id self.pacient_id = pacient_id @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all()
class VaccineModel(BaseModel): __tablename__ = "vacunas" vaccine_type_id = Column("tipo_vacunas_id", Integer, ForeignKey('tipo_vacunas.id')) pacient_id = Column("pacientes_id", Integer, ForeignKey('pacientes.id')) def __init__(self, vaccine_type_id, pacient_id): self.vaccine_type_id = vaccine_type_id self.pacient_id = pacient_id @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all()
class PersonalBackgroundModel(BaseModel): __tablename__ = "antecedentes_personales" personal_background_type_id = Column("antecedentes_id", Integer, ForeignKey('antecedentes.id')) pacient_id = Column("pacientes_id", Integer, ForeignKey('pacientes.id')) def __init__(self, personal_background_type_id, pacient_id): self.personal_background_type_id = personal_background_type_id self.pacient_id = pacient_id @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all()
class MetadataModel(BaseModel): __tablename__ = "metadatos" metadata_type_id = Column("tipo_metadatos_id", Integer, ForeignKey(MetadataTypeModel.id)) clinical_story_id = Column("historias_clinicas_id", Integer, ForeignKey('historias_clinicas.id')) relevant = Column("relevante", Boolean, nullable=False) @classmethod def find_by_story_id(cls, story_id: str) -> "ExamResultModel": return cls.query.filter_by(clinical_story_id=story_id).all() @classmethod def find_by_metadata_id(cls, metadata_id: str) -> "ExamResultModel": return cls.query.filter_by(metadata_type_id=metadata_id).all()
class MedicineModel(BaseModel): __tablename__ = "medicaciones" medicine_type_id = Column("medicamentos_id", Integer, ForeignKey(MedicineTypeModel.id)) clinical_story_id = Column("historias_clinicas_id", Integer, ForeignKey('historias_clinicas.id')) background = Column("antecedente", Boolean) @classmethod def get_list(cls, query_params=None) -> "ExamTypeModel": query = cls.query return query.all() @classmethod def find_by_story_id(cls, story_id: str) -> "ExamResultModel": return cls.query.filter_by(clinical_story_id=story_id).all()
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 ProfessionHistoryModel(BaseModel): __tablename__ = "profesion" profession_type_id = Column("tipo_profesiones_id", Integer, ForeignKey(ProfessionTypeModel.id)) pacient_id = Column("pacientes_id", Integer, ForeignKey('pacientes.id')) start = Column("inicio", Date) end = Column("fin", Date) def __init__(self, profession_type_id, pacient_id, start=None, end=None): self.profession_type_id = profession_type_id self.pacient_id = pacient_id self.start = start self.end = end @classmethod def find_by_pacient_id(cls, pacient_id: str) -> "ClinicalStoryModel": return cls.query.filter_by(pacient_id=pacient_id).all()
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 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 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 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 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()