canvas-medical / canvas-plugins

1 stars 0 forks source link

Add many command origination effects. #63

Closed aduane closed 3 months ago

aduane commented 3 months ago

https://canvasmedical.atlassian.net/browse/KOALA-1632

With this PR, I was able to originate the following commands:

This won't have an effect until we write the interpreters, however.

aduane commented 3 months ago

Here is a sample protocol I was using for development:

import json

from datetime import datetime

from canvas_sdk.effects import Effect, EffectType
from canvas_sdk.commands import (
    AssessCommand,
    DiagnoseCommand,
    GoalCommand,
    HistoryOfPresentIllnessCommand,
    MedicationStatementCommand,
    PlanCommand,
    PrescribeCommand,
    QuestionnaireCommand,
    ReasonForVisitCommand,
    StopMedicationCommand,
    UpdateGoalCommand,
)
from canvas_sdk.events import EventType
from canvas_sdk.protocols import BaseProtocol
from logger import log

class Protocol(BaseProtocol):
    RESPONDS_TO = EventType.Name(EventType.ASSESS_COMMAND__CONDITION_SELECTED)
    #RESPONDS_TO = EventType.Name(EventType.UPDATE_GOAL_COMMAND__POST_DELETE)
    #RESPONDS_TO = EventType.Name(EventType.MEDICATION_STATEMENT_COMMAND__POST_DELETE)

    def compute(self):
        ## assess = AssessCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     narrative="Let's assess",
        ##     status=AssessCommand.Status.STABLE,
        ##     background="this is the background",
        ##     condition_id=self.context["data"]["condition"]["id"]
        ## )
        ## diagnose = DiagnoseCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     icd10_code="F419",
        ##     background="In today's modern world...",
        ##     approximate_date_of_onset=datetime.strptime("2024-06-23", "%Y-%m-%d"),
        ##     today_assessment="Pt needs to log off for at least a month.",
        ## )
        ## goal = GoalCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     goal_statement="Eat a ton of tacos",
        ##     start_date=datetime.strptime("2024-06-23", "%Y-%m-%d"),
        ##     due_date=datetime.strptime("2024-07-23", "%Y-%m-%d"),
        ##     achievement_status=GoalCommand.AchievementStatus.NO_PROGRESS,
        ##     priority=GoalCommand.Priority.HIGH,
        ##     progress="Pt is researching local taquerias.",
        ## )
        ## hpi = HistoryOfPresentIllnessCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     narrative="Read too much twitter, got sad."
        ## )
        ## medication_statement = MedicationStatementCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     fdb_code="218832",
        ##     sig="A flintstone a day keeps the scurvy away."
        ## )
        ## plan = PlanCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     narrative="What's the plan?"
        ## )
        ## unstructured_reason_for_visit = ReasonForVisitCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     structured=False,
        ##     comment="Dropped in for yearly exam",
        ## )
        ## structured_reason_for_visit = ReasonForVisitCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     structured=True,
        ##     coding={
        ##         "code": "129007",
        ##         "system": "http://snomed.info/sct",
        ##     },
        ##     comment="Dropped in for daily exam",
        ## )
        ## stop_medication = StopMedicationCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     medication_id=self.context["data"]["medication"]["id"],
        ##     rationale="I'm sorry Dave, I'm afraid I can't do that",
        ## )
        ## questionnaire = QuestionnaireCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     questionnaire_id="678b901b-a50d-4dfa-bc77-78f1142362fe"
        ## )
        ## update_goal = UpdateGoalCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     goal_id=self.context["data"]["goal"]["id"],
        ##     due_date=datetime.strptime("2030-01-22", "%Y-%m-%d"),
        ##     achievement_status=UpdateGoalCommand.AchievementStatus.IN_PROGRESS,
        ##     priority=UpdateGoalCommand.Priority.LOW,
        ##     progress="hello to this update goal command",
        ## )
        ## prescribe = PrescribeCommand(
        ##     user_id=0,
        ##     note_uuid=self.context["note"]["uuid"],
        ##     fdb_code='197702',
        ##     icd10_codes=['W5621XA'],  # TODO: needs to be condition uuids
        ##     sig='i po qhs',
        ##     days_supply=90,
        ##     quantity_to_dispense=90,
        ##     type_to_dispense='tablet',  # TODO: needs some work
        ##     refills=2,
        ##     substitutions=PrescribeCommand.Substitutions.ALLOWED,
        ##     pharmacy='1051008',
        ##     prescriber_id='3640cd20de8a470aa570a852859ac87e',
        ##     note_to_pharmacist='Hello',
        ## )

        return [
            ## assess.originate(),
            ## diagnose.originate(),
            ## goal.originate(),
            ## hpi.originate(),
            ## medication_statement.originate(),
            ## plan.originate(),
            ## unstructured_reason_for_visit.originate(),
            ## structured_reason_for_visit.originate(),
            ## stop_medication.originate(),
            ## questionnaire.originate(),
            ## prescribe.originate(),
            ## update_goal.originate(),
        ]
aduane commented 3 months ago

@jrwils @mbiannaccone This is ready for review