Skip to content

Commit

Permalink
feat: add line_number option when originating command (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamagalhaes authored Nov 21, 2024
1 parent 53fd89b commit 791d446
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 13 deletions.
3 changes: 2 additions & 1 deletion canvas_sdk/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def command_schema(cls) -> dict:
if name not in base_properties
}

def originate(self) -> Effect:
def originate(self, line_number: int = -1) -> Effect:
"""Originate a new command in the note body."""
self._validate_before_effect("originate")
return Effect(
Expand All @@ -92,6 +92,7 @@ def originate(self) -> Effect:
{
"note": self.note_uuid,
"data": self.values,
"line_number": line_number,
}
),
)
Expand Down
19 changes: 11 additions & 8 deletions canvas_sdk/v1/data/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Container
from typing import TYPE_CHECKING, Type, cast
from typing import TYPE_CHECKING, Self, Type, cast

from django.db import models
from django.db.models import Q
Expand All @@ -11,25 +11,28 @@
class CommittableModelManager(models.Manager):
"""A manager for commands that can be committed."""

def get_queryset(self) -> "models.QuerySet":
def get_queryset(self) -> "CommittableQuerySet":
"""Return a queryset that filters out deleted objects."""
# TODO: Should we just filter these out at the view level?
return super().get_queryset().filter(deleted=False)
return CommittableQuerySet(self.model, using=self._db).filter(deleted=False)

def committed(self) -> "models.QuerySet":

class CommittableQuerySet(models.QuerySet):
"""A queryset for committable objects."""

def committed(self) -> "Self":
"""Return a queryset that filters for objects that have been committed."""
# The committer_id IS set, and the entered_in_error_id IS NOT set
return self.filter(committer_id__isnull=False, entered_in_error_id__isnull=True)

def for_patient(self, patient_id: str) -> "models.QuerySet":
def for_patient(self, patient_id: str) -> "Self":
"""Return a queryset that filters objects for a specific patient."""
return self.filter(patient__id=patient_id)


class ValueSetLookupQuerySet(models.QuerySet):
class ValueSetLookupQuerySet(CommittableQuerySet):
"""A QuerySet that can filter objects based on a ValueSet."""

def find(self, value_set: Type["ValueSet"]) -> models.QuerySet:
def find(self, value_set: Type["ValueSet"]) -> "Self":
"""
Filters conditions, medications, etc. to those found in the inherited ValueSet class that is passed.
Expand Down
8 changes: 6 additions & 2 deletions canvas_sdk/v1/data/condition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.db import models

from canvas_sdk.v1.data.base import CommittableModelManager, ValueSetLookupQuerySet
from canvas_sdk.v1.data.base import (
CommittableModelManager,
CommittableQuerySet,
ValueSetLookupQuerySet,
)
from canvas_sdk.v1.data.patient import Patient
from canvas_sdk.v1.data.user import CanvasUser

Expand All @@ -19,7 +23,7 @@ class Meta:
app_label = "canvas_sdk"
db_table = "canvas_sdk_data_api_condition_001"

objects = CommittableModelManager.from_queryset(ConditionQuerySet)()
objects = ConditionQuerySet.as_manager()

id = models.UUIDField()
dbid = models.BigIntegerField(primary_key=True)
Expand Down
2 changes: 1 addition & 1 deletion canvas_sdk/v1/data/patient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Self
from typing import TYPE_CHECKING, Self

from django.db import models

Expand Down
1 change: 1 addition & 0 deletions plugin_runner/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"operator",
"pickletools",
"random",
"rapidfuzz",
"re",
"requests",
"string",
Expand Down
102 changes: 101 additions & 1 deletion poetry.lock

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

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pydantic = "^2.6.1"
pyjwt = "2.10.0"
python = ">=3.11,<3.13"
python-dotenv = "^1.0.1"
rapidfuzz = "^3.10.1"
redis = "^5.0.4"
requests = "*"
restrictedpython = "^7.1"
Expand Down Expand Up @@ -123,6 +124,7 @@ norecursedirs = [
".mypy_cache",
".pytest_cache",
"__pycache__",
"custom-plugins",
"node_modules",
"static",
"static-files"
Expand Down

0 comments on commit 791d446

Please sign in to comment.