Skip to content

Commit

Permalink
Merge pull request #38 from PerfectFit-project/291-implement-dialog-r…
Browse files Browse the repository at this point in the history
…elapse

291 implement dialog relapse schema.
  • Loading branch information
bscheltinga authored Dec 5, 2022
2 parents e2dbadb + 3048aab commit 2fa3314
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 34 deletions.
67 changes: 67 additions & 0 deletions dbschema/migrations/versions/dcd3663ba17d_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""empty message
Revision ID: dcd3663ba17d
Revises: 258f980de9f2
Create Date: 2022-12-05 08:45:44.942657
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'dcd3663ba17d'
down_revision = '258f980de9f2'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('closed_answers',
sa.Column('closed_answers_id', sa.Integer(), nullable=False),
sa.Column('question_id', sa.Integer(), nullable=True),
sa.Column('answer_value', sa.Integer(), nullable=True),
sa.Column('answer_description', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['question_id'], ['dialog_questions.question_id'], ),
sa.PrimaryKeyConstraint('closed_answers_id')
)
op.create_table('dialog_open_answers',
sa.Column('dialog_open_answers_id', sa.Integer(), nullable=False),
sa.Column('users_nicedayuid', sa.Integer(), nullable=True),
sa.Column('question_id', sa.Integer(), nullable=True),
sa.Column('answer_value', sa.String(), nullable=True),
sa.Column('datetime', sa.TIMESTAMP(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['question_id'], ['dialog_questions.question_id'], ),
sa.ForeignKeyConstraint(['users_nicedayuid'], ['users.nicedayuid'], ),
sa.PrimaryKeyConstraint('dialog_open_answers_id')
)
op.create_table('dialog_closed_answers',
sa.Column('dialog_closed_answers_id', sa.Integer(), nullable=False),
sa.Column('users_nicedayuid', sa.Integer(), nullable=True),
sa.Column('closed_answers_id', sa.Integer(), nullable=True),
sa.Column('datetime', sa.TIMESTAMP(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['closed_answers_id'], ['closed_answers.closed_answers_id'], ),
sa.ForeignKeyConstraint(['users_nicedayuid'], ['users.nicedayuid'], ),
sa.PrimaryKeyConstraint('dialog_closed_answers_id')
)
op.drop_table('dialog_answers')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('dialog_answers',
sa.Column('answer_id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('users_nicedayuid', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('answer', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('question_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('datetime', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['question_id'], ['dialog_questions.question_id'], name='dialog_answers_question_id_fkey'),
sa.ForeignKeyConstraint(['users_nicedayuid'], ['users.nicedayuid'], name='dialog_answers_users_nicedayuid_fkey'),
sa.PrimaryKeyConstraint('answer_id', name='dialog_answers_pkey')
)
op.drop_table('dialog_closed_answers')
op.drop_table('dialog_open_answers')
op.drop_table('closed_answers')
# ### end Alembic commands ###
39 changes: 33 additions & 6 deletions dbschema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,57 @@ class Users(Base):
dob = Column(Date)

# Refer to relationships
dialog_answers = relationship('DialogAnswers')
dialog_closed_answers = relationship('DialogClosedAnswers')
dialog_open_answers = relationship('DialogOpenAnswers')
user_intervention_state = relationship("UserInterventionState", back_populates="user")
user_preferences = relationship("UserPreferences", back_populates="user")
first_aid_kit = relationship("FirstAidKit", back_populates="user")
intervention_activities_performed = relationship("InterventionActivitiesPerformed", back_populates="user")


class DialogAnswers(Base):
__tablename__ = 'dialog_answers'
answer_id = Column(Integer, primary_key=True)
class DialogClosedAnswers(Base):
__tablename__ = 'dialog_closed_answers'
dialog_closed_answers_id = Column(Integer, primary_key=True)
users_nicedayuid = Column(Integer, ForeignKey('users.nicedayuid'))
closed_answers_id = Column(Integer, ForeignKey('closed_answers.closed_answers_id'))
datetime = Column(TIMESTAMP(timezone=True), default=func.now())

# Refer relationship
closed_answers = relationship('ClosedAnswers')


class DialogOpenAnswers(Base):
__tablename__ = 'dialog_open_answers'
dialog_open_answers_id = Column(Integer, primary_key=True)
users_nicedayuid = Column(Integer, ForeignKey('users.nicedayuid'))
answer = Column(String)
question_id = Column(Integer, ForeignKey('dialog_questions.question_id'))
answer_value = Column(String)
datetime = Column(TIMESTAMP(timezone=True), default=func.now())

# Refer relationship
dialog_questions = relationship('DialogQuestions')
dialog_questions = relationship("DialogQuestions", back_populates="dialog_open_answers")


class ClosedAnswers(Base):
__tablename__ = 'closed_answers'
closed_answers_id = Column(Integer, primary_key=True)
question_id = Column(Integer, ForeignKey('dialog_questions.question_id'))
answer_value = Column(Integer)
answer_description = Column(String)

# Refer relationship
dialog_questions = relationship("DialogQuestions", back_populates="closed_answers")


class DialogQuestions(Base):
__tablename__ = 'dialog_questions'
question_id = Column(Integer, primary_key=True)
question_description = Column(String)

# Refer relationships
dialog_open_answers = relationship("DialogOpenAnswers", back_populates="dialog_questions")
closed_answers = relationship("ClosedAnswers", back_populates="dialog_questions")


class FirstAidKit(Base):
__tablename__ = "first_aid_kit"
Expand Down
31 changes: 31 additions & 0 deletions helper/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,41 @@ class ExecutionInterventionComponents(str, Enum):
GENERAL_ACTIVITY = 'general_activity'
WEEKLY_REFLECTION = 'weekly_reflection'
DAILY_REFLECTION = 'daily_reflection'
RELAPSE_DIALOG = 'relapse_dialog'


class ExecutionInterventionComponentsTriggers(str, Enum):
EXECUTION_INTRODUCTION = 'EXTERNAL_trigger_execution_introduction'
GENERAL_ACTIVITY = 'EXTERNAL_trigger_general_activity'
WEEKLY_REFLECTION = 'EXTERNAL_weekly_reflection'
DAILY_REFLECTION = 'EXTERNAL_daily_reflection'
RELAPSE_DIALOG = 'EXTERNAL_relapse_dialog'


class DialogQuestionsEnum(Enum):
FUTURE_SELF_SMOKER_WORDS = 1 # Which three words suits you as smoker?
FUTURE_SELF_SMOKER_WHY = 2 # Why did you pick these words for smoking?
FUTURE_SELF_MOVER_WORDS = 3 # Which three words suits you as exerciser?
FUTURE_SELF_MOVER_WHY = 4 # Why did you pick these words for exercising?
FUTURE_SELF_I_SEE_MYSELF_AS_SMOKER = 5 # I see myself as smoker, non-smoker or quitter
FUTURE_SELF_I_SEE_MYSELF_AS_MOVER = 6 # I see myself as active, bit active or not active
RELAPSE_CRAVING_WHAT_DOING = 7
RELAPSE_CRAVING_HOW_FEEL = 8
RELAPSE_CRAVING_WITH_WHOM = 9
RELAPSE_CRAVING_HAPPENED_SPECIAL = 10
RELAPSE_LAPSE_TYPE_SMOKE = 11
RELAPSE_LAPSE_NUMBER_CIGARETTES = 12
RELAPSE_LAPSE_WHAT_DOING = 13
RELAPSE_LAPSE_HOW_FEEL = 14
RELAPSE_LAPSE_WITH_WHOM = 15
RELAPSE_LAPSE_HAPPENED_SPECIAL = 16
RELAPSE_RELAPSE_TYPE_SMOKE = 17
RELAPSE_RELAPSE_NUMBER_CIGARETTES = 18
RELAPSE_RELAPSE_WHAT_DOING = 19
RELAPSE_RELAPSE_HOW_FEEL = 20
RELAPSE_RELAPSE_WITH_WHOM = 21
RELAPSE_RELAPSE_HAPPENED_SPECIAL = 22
RELAPSE_PA_TOGETHER = 23
RELAPSE_PA_WHY_FAIL = 24
RELAPSE_PA_DOING_TODAY = 25
RELAPSE_PA_HAPPENED_SPECIAL = 26
Loading

0 comments on commit 2fa3314

Please sign in to comment.