Goals
The Goals API is responsible for managing goals. The API provides events so you can react to creating, updating, and closing a Goal
Events
The following events are emitted:
- class canvas_core.goals.events.GoalEvent(**attrs: Any)
Base class for all Goal-related events, so they all have the same properties.
- class canvas_core.goals.events.GoalUpdateData
Class to Update/Close event method to add diffable data.
- class canvas_core.goals.events.PostGoalClose(**attrs: Any)
Emitted after a Goal is closed.
- class canvas_core.goals.events.PostGoalCreate(**attrs: Any)
Emitted after a Goal is created.
- class canvas_core.goals.events.PostGoalUpdate(**attrs: Any)
Emitted after a Goal is updated.
- class canvas_core.goals.events.PreGoalClose(**attrs: Any)
Emitted before a Goal is closed.
- class canvas_core.goals.events.PreGoalCreate(**attrs: Any)
Emitted before a Goal is created.
- class canvas_core.goals.events.PreGoalUpdate(**attrs: Any)
Emitted before a Goal is updated.
Examples
from typing import Any
from canvas_core import events, logging
from canvas_core.goals.events import PostGoalCreate, PostGoalUpdate, PreGoalClose, PostGoalClose
logger = logging.get_logger(__name__)
@events.handle_event(PostGoalCreate)
def handle_new_goal(event: PostGoalCreate) -> None:
logger.info("Goal created!", externally_exposable_id=event.externally_exposable_id,
lifecycle_status=event.lifecycle_status,
achievement_status=event.achievement_status,
progress=event.progress)
@events.handle_event(PostGoalUpdate)
def handle_goal_updated(event: PostGoalUpdate) -> None:
logger.info("Goal updated!", externally_exposable_id=event.externally_exposable_id,
lifecycle_status=event.lifecycle_status,
new_lifecycle_status=event.new_lifecycle_status,
old_achievement_status=event.achievement_status,
new_achievement_status=event.new_achievement_status,
progress=event.progress,
new_progress=event.new_progress,
)
@events.handle_event(PreGoalClose)
def handle_before_goal_close(event: PreGoalClose) -> None:
logger.info("Goal will be closed!", externally_exposable_id=event.externally_exposable_id,
lifecycle_status=event.lifecycle_status,
new_lifecycle_status=event.new_lifecycle_status,
old_achievement_status=event.achievement_status,
new_achievement_status=event.new_achievement_status,
progress=event.progress,
new_progress=event.new_progress,
)
@events.handle_event(PostGoalClose)
def handle_goal_close(event: PostGoalClose) -> None:
logger.info("Goal closed!", externally_exposable_id=event.externally_exposable_id,
lifecycle_status=event.lifecycle_status,
new_lifecycle_status=event.new_lifecycle_status,
old_achievement_status=event.achievement_status,
new_achievement_status=event.new_achievement_status,
progress=event.progress,
new_progress=event.new_progress,
)
API Reference
- class canvas_core.goals.models.Goal(*args, **kwargs)
A new goal, where a goal is a desired health state to be achieved by a patient.
- class AchievementStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
- exception DoesNotExist
- class LifecycleStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
- exception MultipleObjectsReturned
- class canvas_core.goals.models.UpdateGoal(*args, **kwargs)
An update to a goal, where a goal is a desired health state for a patient.
The update may involve changing the goal’s attributes like achievement status and lifecycle status, which corresponds to both ‘Update goal’ and ‘Close goal’ commands.
- exception DoesNotExist
- exception MultipleObjectsReturned