|
6 | 6 | from state_machine.const import (REDIS_URL, TIMEZONE, TRIGGER_COMPONENT, |
7 | 7 | SCHEDULE_TRIGGER_COMPONENT, TRIGGER_INTENT) |
8 | 8 | from virtual_coach_db.dbschema.models import (ClosedAnswers, DialogClosedAnswers, DialogQuestions, |
| 9 | + InterventionActivitiesPerformed, |
9 | 10 | InterventionComponents, InterventionPhases, Users, |
10 | 11 | UserStateMachine, UserInterventionState) |
11 | 12 | from virtual_coach_db.helper.definitions import Components, ComponentsTriggers, DialogQuestionsEnum |
@@ -76,6 +77,40 @@ def create_new_date(start_date: date, |
76 | 77 | return new_timedate |
77 | 78 |
|
78 | 79 |
|
| 80 | +def get_activity_completion_state(user_id: int, activity_id: int) -> Optional[bool]: |
| 81 | + """ |
| 82 | + Get the completion state of an intervention activity |
| 83 | + (they are completed in the general activity dialog) |
| 84 | + Args: |
| 85 | + user_id: the id of the user |
| 86 | + activity_id: id of the activity, as reported in the intervention_activity table |
| 87 | +
|
| 88 | + Returns: True if the activity has been completed, False otherwise |
| 89 | +
|
| 90 | + """ |
| 91 | + |
| 92 | + session = get_db_session() |
| 93 | + |
| 94 | + activities = ( |
| 95 | + session.query( |
| 96 | + InterventionActivitiesPerformed |
| 97 | + ) |
| 98 | + .filter( |
| 99 | + InterventionActivitiesPerformed.users_nicedayuid == user_id, |
| 100 | + InterventionActivitiesPerformed.intervention_activity_id == activity_id |
| 101 | + ) |
| 102 | + .limit(1) # get only the first result |
| 103 | + .one_or_none() |
| 104 | + ) |
| 105 | + |
| 106 | + if activities is not None: |
| 107 | + session.close() |
| 108 | + return True |
| 109 | + |
| 110 | + session.close() |
| 111 | + return False |
| 112 | + |
| 113 | + |
79 | 114 | def get_all_scheduled_occurrence(user_id: int, |
80 | 115 | intervention_component_id: int, |
81 | 116 | current_date: datetime) -> Optional[UserInterventionState]: |
|
0 commit comments