Latest SIG not reliably available from a single Canvas read source after ChangeMedicationCommand #1611
Replies: 2 comments 4 replies
|
Hi @jayant-walvekar-falconeer , How latest_sig worksThe "latest SIG" shown in the patient chart is not a stored field on the Medication record — it's a computed property that Canvas calculates on the fly each time it's read. It searches across all committed commands that can carry a SIG for that medication and returns the one from the most recent note (by date of service). The priority order is: This is why you're seeing the SIG spread across multiple sources — it's not inconsistency, it's that Canvas intentionally derives the "current" SIG from the most recent command rather than storing it in one place. A ChangeMedicationCommand commit writes the SIG to its own record but doesn't overwrite any field on the Medication or MedicationStatement model. Reading the latest SIGVia FHIR API (recommended for external integrations):The computed latest_sig is returned in the MedicationStatement resource's dosage[0].text field: This returns the same value displayed in the chart. The value is available immediately after commit — there is no async delay. Via SDK (for use within plugins):The latest_sig property is not currently exposed in the SDK data models. However, you can replicate the same logic by querying the Command model. The SIG is stored in each command's data JSON field under the key sig: The medication_dbid is the integer database ID of the Medication (available as medication.dbid in the SDK). Since commands are ordered by note date of service descending, the first match for your medication is the most recent SIG — matching the same logic the chart uses. Regarding ChangeMedication not appearing in the noteYou mentioned that the ChangeMedicationCommand doesn't appear in the note on the UI. Can you share more details on this — specifically which note you're looking at and how the command was originated (via the UI, a plugin, or the API)? The command should appear in the note body regardless of how it was created, so we'd like to understand what you're seeing to help debug. Or you can open a support ticket for this specific issue, because we may have a bug we need to look into more. Let us know if you have any other questions! |
|
Point 1 — latest_sig logic: Thank you for the detailed explanation of how latest_sig is computed. I have updated my plugin to replicate this logic — querying across all five command types (changeMedication, prescribe, refill, adjustPrescription, medicationStatement) ordered by note datetime_of_service. However, I would like to understand the design rationale here. The SIG is conceptually a property of the medication. It is what the patient sees and what clinicians' reference. But to read the current SIG, an App has to query the Command model across five different schema keys, understand the different reference key structures (medication.value vs prescribe.value vs medication_statement.value), and implement date-based priority ordering. This feels like an internal implementation detail that's been pushed to the plugin consumer. Is there a reason latest_sig isn't exposed as a computed property on the Medication data model in the SDK? Or surfaced through a helper/utility? I noticed the FHIR API does return it cleanly via dosage[0].text on MedicationStatement, but for plugins that use the SDK there's no equivalent. I have to rebuild the derivation logic ourselves. I want to make sure I am not missing a simpler path. If this is truly the intended design for SDK consumers, I will work with it — but it would be great to know if there are any plans to expose this more directly. Any change in this model will break my code. Point 2 — ChangeMedicationCommand not rendering in note UI: How I create the command in our plugin: Note already exists and is editablenote = Note.objects.get(id=note_key) medication_id is the UUID from Medication model (Patient.medications → med.id)command = ChangeMedicationCommand( When I list all the notes using plugin API and look at this particular note object, I see that the note ash The command is originated, committed, and present in the note body — but the Canvas UI renders the note as empty. StopMedicationCommand using the same pattern renders correctly with "Stop Medication: ..." in the UI. Could you check if there's a rendering issue for plugin-originated changeMedication commands? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We are updating medication SIG using the Canvas SDK
ChangeMedicationCommand(originate + commit on a note).Issue:
After the command is committed, we are not consistently able to read the latest SIG back from a single Canvas medication read source.
Important:
This issue happens always, not intermittently.
What we observe:
ChangeMedicationCommandin notesQuestions:
ChangeMedicationCommandis committed, what is the correct read path for the latest SIG?All reactions