Command
Introduction #
The Command model represents a command in a note.
Basic usage #
To get a command by identifier, use the get method on the Command model manager:
from canvas_sdk.v1.data.command import Command
command = Command.objects.get(id="b80b1cdc-2e6a-4aca-90cc-ebc02e683f35")
Filtering #
Commands can be filtered by any attribute that exists on the model.
Filtering for commands is done with the filter method on the Command model manager.
By attribute #
Specify an attribute with filter to filter by that attribute:
from canvas_sdk.v1.data.command import Command
commands = Command.objects.filter(state="committed")
Command types and data #
When events are fired as part of Command Lifecycle Events, the self.target value that is available within a plugin will contain the id value of the command. For example:
from canvas_sdk.protocols import BaseProtocol
from canvas_sdk.effects import Effect
from canvas_sdk.events import EventType
from logger import log
class Protocol(BaseProtocol):
RESPONDS_TO = [
EventType.Name(EventType.REASON_FOR_VISIT_COMMAND__POST_UPDATE),
]
def compute(self) -> list[Effect]:
log.info(self.target) # logs the Command id
Using this value, the Command model can be queried to fetch additional data about the command. Two main fields to pay attention to here are the schema_key and data fields. The schema_key field contains the type of the command, while the data field contains a JSON object with command data as key/value pairs:
import json
from canvas_sdk.effects import Effect
from canvas_sdk.protocols import BaseProtocol
from canvas_sdk.v1.data.command import Command
from logger import log
class Protocol(BaseProtocol):
def compute(self) -> list[Effect]:
command_instance = Command.objects.get(id=self.target)
log.info(command_instance.schema_key)
log.info(json.dumps(command_instance.data, indent=2))
For example, for a Reason For Visit command, the preceding code would log the following lines:
reasonForVisit
{
"coding": {
"text": "Accident-prone",
"extra": null,
"value": "165002",
"disabled": false,
"annotations": null,
"description": null
},
"comment": "Patient would like to discuss condition."
}
The following table shows the different command schema_key values with links to their respective Command Modules. The attributes shown in each corresponding entry contain the structure that will appear in the data JSON field of each Command.
| Schema Key | Command Data |
|---|---|
| adjustPrescription | AdjustPrescription |
| allergy | Allergy |
| assess | Assess |
| changeMedication | ChangeMedication |
| closeGoal | CloseGoal |
| diagnose | Diagnose |
| familyHistory | FamilyHistory |
| followUp | FollowUp |
| goal | Goal |
| hpi | HistoryOfPresentIllness |
| imagingOrder | ImagingOrder |
| instruct | Instruct |
| labOrder | LabOrder |
| medicalHistory | MedicalHistory |
| medicationStatement | MedicationStatement |
| perform | Perform |
| plan | Plan |
| prescribe | Prescribe |
| questionnaire | Questionnaire |
| reasonForVisit | ReasonForVisit |
| refer | Refer |
| refill | Refill |
| removeAllergy | RemoveAllergy |
| resolveCondition | ResolveCondition |
| stopMedication | StopMedication |
| surgicalHistory | SurgicalHistory |
| task | Task |
| updateDiagnosis | UpdateDiagnosis |
| updateGoal | UpdateGoal |
| vitals | Vitals |
PLEASE NOTE the Commands Module is under development and Canvas is working to migrate all commands to be available. This means that some commands are not able to emit events available in plugins, and historical commands created prior to their Commands Module availability may not be able to be queried using the data module. This product updates table shows the commands and their release statuses. If a command in a chart is not available by querying the Command data model, the data is still available to be queried using corresponding data models (i.e. Questionnaire, ImagingOrder, etc.).
Attributes #
Command #
| Field Name | Type |
|---|---|
| id | UUID |
| dbid | Integer |
| created | DateTime |
| modified | DateTime |
| originator | CanvasUser |
| committer | CanvasUser |
| entered_in_error | CanvasUser |
| state | String |
| patient | Patient |
| note | Note |
| schema_key | String |
| data | JSON |
| origination_source | String |