Skip to content

Commit

Permalink
feat: add protocol classname to effects and include in plugin_runner …
Browse files Browse the repository at this point in the history
…event handler (#145)
  • Loading branch information
mbiannaccone authored Oct 29, 2024
1 parent 5dd7d96 commit 517cadb
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 11 deletions.
4 changes: 4 additions & 0 deletions canvas_cli/apps/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def _get_meta_properties(protocol_path: Path, classname: str) -> dict[str, str]:
value = meta_b.value.value
elif isinstance(meta_b.value, ast.List):
value = [e.value for e in meta_b.value.elts]
elif isinstance(meta_b.value, ast.Dict):
keys = meta_b.value.keys
values = meta_b.value.values
value = {k.value: values[i].value for i, k in enumerate(keys)}
else:
value = None
meta[target_id] = value
Expand Down
10 changes: 5 additions & 5 deletions canvas_generated/messages/effects_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions canvas_generated/messages/effects_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ ANNOTATE_CLAIM_CONDITION_RESULTS: EffectType
SHOW_PATIENT_CHART_SUMMARY_SECTIONS: EffectType

class Effect(_message.Message):
__slots__ = ("type", "payload", "plugin_name")
__slots__ = ("type", "payload", "plugin_name", "classname")
TYPE_FIELD_NUMBER: _ClassVar[int]
PAYLOAD_FIELD_NUMBER: _ClassVar[int]
PLUGIN_NAME_FIELD_NUMBER: _ClassVar[int]
CLASSNAME_FIELD_NUMBER: _ClassVar[int]
type: EffectType
payload: str
plugin_name: str
def __init__(self, type: _Optional[_Union[EffectType, str]] = ..., payload: _Optional[str] = ..., plugin_name: _Optional[str] = ...) -> None: ...
classname: str
def __init__(self, type: _Optional[_Union[EffectType, str]] = ..., payload: _Optional[str] = ..., plugin_name: _Optional[str] = ..., classname: _Optional[str] = ...) -> None: ...
2 changes: 1 addition & 1 deletion canvas_generated/messages/events_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion canvas_generated/messages/plugins_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion canvas_generated/services/plugin_runner_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions canvas_sdk/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from canvas_sdk.protocols.base import BaseProtocol
from canvas_sdk.protocols.clinical_quality_measure import ClinicalQualityMeasure
1 change: 1 addition & 0 deletions canvas_sdk/protocols/clinical_quality_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Meta:
description: str = ""
information: str = ""
references: list[str] = []
source_attributes: dict[str, str]
types: list[str] = []
authors: list[str] = []
show_in_chart: bool = True
Expand Down
13 changes: 12 additions & 1 deletion plugin_runner/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from canvas_sdk.effects import Effect
from canvas_sdk.events import Event, EventResponse, EventType
from canvas_sdk.protocols import ClinicalQualityMeasure
from canvas_sdk.utils.stats import get_duration_ms, tags_to_line_protocol
from logger import log

Expand Down Expand Up @@ -80,11 +81,21 @@ async def HandleEvent(self, request: Event, context: Any) -> EventResponse:

try:
protocol = protocol_class(request, secrets)
classname = (
protocol.__class__.__name__
if isinstance(protocol, ClinicalQualityMeasure)
else None
)

compute_start_time = time.time()
_effects = await asyncio.get_running_loop().run_in_executor(None, protocol.compute)
effects = [
Effect(type=effect.type, payload=effect.payload, plugin_name=base_plugin_name)
Effect(
type=effect.type,
payload=effect.payload,
plugin_name=base_plugin_name,
classname=classname,
)
for effect in _effects
]
compute_duration = get_duration_ms(compute_start_time)
Expand Down
1 change: 1 addition & 0 deletions protobufs/canvas_generated/messages/effects.proto
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ message Effect {
EffectType type = 1;
string payload = 2;
string plugin_name = 3;
string classname = 4;
//Oneof effect_payload {
// ...
//}
Expand Down

0 comments on commit 517cadb

Please sign in to comment.