Skip to content

Add patient tags support to protocol variables - #673

Merged
marceloarocha merged 1 commit into
developfrom
claude/pessoa-marcadores-protocol-var-k2st8c
Sep 6, 2026
Merged

Add patient tags support to protocol variables#673
marceloarocha merged 1 commit into
developfrom
claude/pessoa-marcadores-protocol-var-k2st8c

Conversation

@marceloarocha

Copy link
Copy Markdown
Collaborator

Summary

Adds support for patient tags as a protocol variable field, allowing protocols to trigger based on tags assigned to patients. Tags are compared using IN/NOTIN operators with case-insensitive matching.

Key Changes

  • Protocol Variable Support: Added tags field to ProtocolVariableFieldEnum to enable tag-based protocol conditions
  • Tag Comparison Logic: Implemented tag matching in alert_protocol.py with:
    • Support for IN/NOTIN operators only (other operators rejected with OPERATOR_NOT_SUPPORTED reason)
    • Case-insensitive comparison (both patient tags and filter values converted to uppercase)
    • Empty tag list handling (patients without tags never match IN, always match NOTIN)
    • Trace details showing matched tags for debugging
  • Agent Tool: Added list_tags() tool to protocol agent to list active patient tags by name, supporting both PATIENT and PATIENT_NAVIGATION tag types
  • Documentation: Updated protocol agent service documentation to describe tags field behavior and usage guidelines
  • Comprehensive Tests: Added 7 new test cases covering:
    • IN/NOTIN operators with matching and non-matching tags
    • Case-insensitive comparison
    • Patients with/without tags
    • Unsupported operator handling
    • Trace output validation with matched tag details

Implementation Details

  • Tags are stored in uppercase in the patient model (per existing patient_service._get_tags convention)
  • Tag comparison normalizes both sides to uppercase for case-insensitive matching
  • Trace output includes matched field showing which tags from the filter list were found in the patient's tags
  • Protocol validation rejects non-list operators (=, <, >, etc.) for tags with appropriate error reason

https://claude.ai/code/session_01UT3SoG4j3iqxMvFiR8N4Tf

Adds the "tags" protocol variable field: a list of patient tag names
(marcador table) tested with IN/NOTIN against Patient.tags. Comparison is
case-insensitive on both sides; a patient without tags never matches IN
and always matches NOTIN.

- AlertProtocol evaluates the new field and reports matched tags in the
  trace; unsupported operators are traced as OPERATOR_NOT_SUPPORTED
- protocol co-pilot gets a list_tags tool and prompt guidance for the field
- unit tests for match/no-match, empty tags, case and trace details

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UT3SoG4j3iqxMvFiR8N4Tf

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR successfully implements patient tag support for protocol variables across all layers of the system. The implementation follows existing patterns consistently and includes comprehensive test coverage. The changes integrate cleanly with the protocol evaluation engine, agent tools, and trace functionality.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@marceloarocha
marceloarocha merged commit 6694167 into develop Sep 6, 2026
10 checks passed
@marceloarocha
marceloarocha deleted the claude/pessoa-marcadores-protocol-var-k2st8c branch September 6, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants