-
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.
chore: local development improvements (#102)
Co-authored-by: José Magalhães <jose.magalhaes@canvasmedical.com>
- Loading branch information
1 parent
3b4d7b5
commit ca4458e
Showing
72 changed files
with
343 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from canvas_cli.apps.emit.emit import emit | ||
|
||
__all__ = ("emit",) |
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,67 @@ | ||
import json | ||
import random | ||
from pathlib import Path | ||
from typing import Annotated | ||
|
||
import grpc | ||
import typer | ||
|
||
from canvas_generated.messages.events_pb2 import Event as PluginRunnerEvent | ||
from canvas_generated.messages.events_pb2 import EventType as PluginRunnerEventType | ||
from canvas_generated.services.plugin_runner_pb2_grpc import PluginRunnerStub | ||
|
||
|
||
def emit( | ||
event_fixture: str, | ||
plugin_runner_port: Annotated[ | ||
str, typer.Option(help="Port of your locally running plugin runner") | ||
] = "50051", | ||
) -> None: | ||
""" | ||
Send an event fixture to your locally running plugin-runner process, and print any resultant effects. | ||
Valid fixture files are newline-delimited JSON, with each containing the keys `EventType`, `target`, and `context`. Some fixture files are included in the canvas-plugins repo. | ||
""" | ||
# If an event fixture file exists at the specified path, use it. | ||
# Otherwise, see if it represents an event that we have a Canvas-provided | ||
# fixture for and use that. | ||
event_fixture_path = Path(event_fixture) | ||
|
||
if not event_fixture_path.exists(): | ||
candidate_built_in_fixture_path = ( | ||
Path(__file__).resolve().parent / "event_fixtures" / f"{event_fixture}.ndjson" | ||
) | ||
if candidate_built_in_fixture_path.exists(): | ||
event_fixture_path = candidate_built_in_fixture_path | ||
else: | ||
print(f"ERROR: No file found at location {event_fixture}.") | ||
print(f"ERROR: No built-in fixture file found named {event_fixture}.ndjson.") | ||
return | ||
|
||
# Grab a random event from the fixture file ndjson | ||
lines = event_fixture_path.read_text().splitlines() | ||
myline = random.choice(lines) | ||
event_data = json.loads(myline) | ||
event = PluginRunnerEvent( | ||
type=PluginRunnerEventType.Value(event_data["EventType"]), | ||
target=event_data["target"], | ||
context=event_data["context"], | ||
) | ||
with grpc.insecure_channel(f"localhost:{plugin_runner_port}") as channel: | ||
stub = PluginRunnerStub(channel) | ||
responses = stub.HandleEvent(event) | ||
|
||
at_least_one_effect = False | ||
try: | ||
for response in responses: | ||
for effect in response.effects: | ||
at_least_one_effect = True | ||
print(effect) | ||
|
||
if not at_least_one_effect: | ||
print("SUCCESS: No effects returned.") | ||
except grpc.RpcError as e: | ||
if e.code() == grpc.StatusCode.UNAVAILABLE: | ||
print( | ||
f"ERROR: Couldn't make a connection to a plugin runner process at localhost:{plugin_runner_port}. Is it running?" | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
from canvas_cli.apps.run_plugins.run_plugins import run_plugin, run_plugins | ||
|
||
__all__ = ("run_plugins", "run_plugin") |
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,16 @@ | ||
from plugin_runner.plugin_runner import run_server | ||
|
||
|
||
def run_plugin(plugin_directory: str) -> None: | ||
""" | ||
Run the specified plugin for local development. | ||
""" | ||
return run_plugins([plugin_directory]) | ||
|
||
|
||
def run_plugins(plugin_directories: list[str]) -> None: | ||
""" | ||
Run the specified plugins for local development. | ||
""" | ||
run_server(plugin_directories) | ||
return |
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
1 change: 0 additions & 1 deletion
1
canvas_cli/templates/plugins/default/{{ cookiecutter.__project_slug }}/README.md
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,27 @@ | ||
from django.db import models | ||
|
||
from canvas_sdk.v1.data.patient import Patient | ||
from canvas_sdk.v1.data.user import CanvasUser | ||
|
||
|
||
class Command(models.Model): | ||
"""Command.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_commands_command_001" | ||
|
||
id = models.UUIDField() | ||
dbid = models.BigIntegerField(primary_key=True) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField() | ||
originator = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
committer = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
entered_in_error = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
state = models.CharField() | ||
patient = models.ForeignKey(Patient, on_delete=models.DO_NOTHING) | ||
note_id = models.BigIntegerField() | ||
schema_key = models.TextField() | ||
data = models.JSONField() | ||
origination_source = models.CharField() |
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,44 @@ | ||
from django.db import models | ||
|
||
from canvas_sdk.v1.data import Patient | ||
from canvas_sdk.v1.data.user import CanvasUser | ||
|
||
|
||
class Device(models.Model): | ||
"""Device.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_device_001" | ||
|
||
id = models.UUIDField() | ||
dbid = models.BigIntegerField(primary_key=True) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField() | ||
originator = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
committer = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
entered_in_error = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
patient = models.ForeignKey(Patient, on_delete=models.DO_NOTHING, related_name="devices") | ||
note_id = models.BigIntegerField() | ||
deleted = models.BooleanField() | ||
labeled_contains_NRL = models.BooleanField() | ||
assigning_authority = models.CharField() | ||
scoping_entity = models.CharField() | ||
udi = models.CharField() | ||
di = models.CharField() | ||
issuing_agency = models.CharField() | ||
lot_number = models.CharField() | ||
brand_name = models.CharField() | ||
mri_safety_status = models.CharField() | ||
version_model_number = models.CharField() | ||
company_name = models.CharField() | ||
gmdnPTName = models.TextField() | ||
status = models.CharField() | ||
expiration_date = models.DateField() | ||
expiration_date_original = models.CharField() | ||
serial_number = models.CharField() | ||
manufacturing_date_original = models.CharField() | ||
manufacturing_date = models.DateField() | ||
manufacturer = models.CharField() | ||
procedure_id = models.BigIntegerField() |
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,117 @@ | ||
from django.db import models | ||
|
||
from canvas_sdk.v1.data.base import CommittableModelManager, ValueSetLookupQuerySet | ||
from canvas_sdk.v1.data.patient import Patient | ||
from canvas_sdk.v1.data.user import CanvasUser | ||
|
||
|
||
class ObservationQuerySet(ValueSetLookupQuerySet): | ||
"""ObservationQuerySet.""" | ||
|
||
pass | ||
|
||
|
||
class Observation(models.Model): | ||
"""Observation.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_observation_001" | ||
|
||
objects = CommittableModelManager.from_queryset(ObservationQuerySet)() | ||
|
||
id = models.UUIDField() | ||
dbid = models.BigIntegerField(primary_key=True) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField() | ||
originator = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
committer = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
entered_in_error = models.ForeignKey(CanvasUser, on_delete=models.DO_NOTHING) | ||
deleted = models.BooleanField() | ||
patient = models.ForeignKey(Patient, on_delete=models.DO_NOTHING, related_name="observations") | ||
is_member_of = models.ForeignKey( | ||
"self", on_delete=models.DO_NOTHING, null=True, related_name="members" | ||
) | ||
category = models.CharField() | ||
units = models.TextField() | ||
value = models.TextField() | ||
note_id = models.BigIntegerField() | ||
name = models.TextField() | ||
effective_datetime = models.DateTimeField() | ||
|
||
|
||
class ObservationCoding(models.Model): | ||
"""ObservationCoding.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_observationcoding_001" | ||
|
||
dbid = models.BigIntegerField(primary_key=True) | ||
system = models.CharField() | ||
version = models.CharField() | ||
code = models.CharField() | ||
display = models.CharField() | ||
user_selected = models.BooleanField() | ||
observation = models.ForeignKey( | ||
Observation, on_delete=models.DO_NOTHING, related_name="codings" | ||
) | ||
|
||
|
||
class ObservationComponent(models.Model): | ||
"""ObservationComponent.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_observationcomponent_001" | ||
|
||
dbid = models.BigIntegerField(primary_key=True) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField() | ||
observation = models.ForeignKey( | ||
Observation, on_delete=models.DO_NOTHING, related_name="components" | ||
) | ||
value_quantity = models.TextField() | ||
value_quantity_unit = models.TextField() | ||
name = models.TextField() | ||
|
||
|
||
class ObservationComponentCoding(models.Model): | ||
"""ObservationComponentCoding.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_observationcomponentcoding_001" | ||
|
||
dbid = models.BigIntegerField(primary_key=True) | ||
system = models.CharField() | ||
version = models.CharField() | ||
code = models.CharField() | ||
display = models.CharField() | ||
user_selected = models.BooleanField() | ||
observation_component = models.ForeignKey( | ||
ObservationComponent, on_delete=models.DO_NOTHING, related_name="codings" | ||
) | ||
|
||
|
||
class ObservationValueCoding(models.Model): | ||
"""ObservationValueCoding.""" | ||
|
||
class Meta: | ||
managed = False | ||
app_label = "canvas_sdk" | ||
db_table = "canvas_sdk_data_api_observationvaluecoding_001" | ||
|
||
dbid = models.BigIntegerField(primary_key=True) | ||
system = models.CharField() | ||
version = models.CharField() | ||
code = models.CharField() | ||
display = models.CharField() | ||
user_selected = models.BooleanField() | ||
observation = models.ForeignKey( | ||
Observation, on_delete=models.DO_NOTHING, related_name="value_codings" | ||
) |
Oops, something went wrong.