-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Command effects and BannerAlert effects
Create Command effects and BannerAlert effects
- Loading branch information
Showing
13 changed files
with
161 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Any | ||
|
||
from pydantic import Field | ||
|
||
from canvas_sdk.effects.banner_alert.constants import ( | ||
BannerAlertIntent, | ||
BannerAlertPlacement, | ||
) | ||
from canvas_sdk.effects.base import _BaseEffect | ||
|
||
|
||
class BannerAlert(_BaseEffect): | ||
""" | ||
An Effect that will result in a banner alert in Canvas. | ||
""" | ||
|
||
class Meta: | ||
effect_type = "SHOW_BANNER_ALERT" | ||
|
||
patient_key: str | ||
narrative: str = Field(max_length=90) | ||
placements: list[BannerAlertPlacement] = Field(min_length=1) | ||
intents: list[BannerAlertIntent] = Field(min_length=1) | ||
|
||
@property | ||
def values(self) -> dict[str, Any]: | ||
"""The BannerAlert's values.""" | ||
return { | ||
"narrative": self.narrative, | ||
"placement": [p.value for p in self.placements], | ||
"intent": [i.value for i in self.intents], | ||
} | ||
|
||
@property | ||
def effect_payload(self) -> dict[str, Any]: | ||
"""The payload of the effect.""" | ||
return {"patient": self.patient_key, "data": self.values} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from enum import Enum | ||
|
||
|
||
class BannerAlertPlacement(Enum): | ||
"""Where the BannerAlert should appear in the Canvas UI.""" | ||
|
||
CHART = "chart" | ||
TIMELINE = "timeline" | ||
APPOINTMENT_CARD = "appointment_card" | ||
SCHEDULING_CARD = "scheduling_card" | ||
PROFILE = "profile" | ||
|
||
|
||
class BannerAlertIntent(Enum): | ||
"""The intent that should be conveyed in the BannerAlert.""" | ||
|
||
INFO = "info" | ||
WARNING = "warning" | ||
ALERT = "alert" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Any | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
|
||
from plugin_runner.generated.messages.effects_pb2 import Effect | ||
|
||
|
||
class _BaseEffect(BaseModel): | ||
""" | ||
A Canvas Effect that changes user behavior or autonomously performs activities on behalf of users. | ||
""" | ||
|
||
class Meta: | ||
effect_type = "" | ||
|
||
model_config = ConfigDict(strict=True, validate_assignment=True) | ||
|
||
@property | ||
def values(self) -> dict[str, Any]: | ||
return {} | ||
|
||
@property | ||
def effect_payload(self) -> dict[str, Any]: | ||
return {"data": self.values} | ||
|
||
def apply(self) -> Effect: | ||
return { | ||
"type": self.Meta.effect_type, | ||
"payload": self.effect_payload, | ||
} |