Rx Stage Needs Attention Task Creation Update

Rx Stage Needs Attention Task Creation Update

Tech brief

Request: When an Rx moves into NEEDS ATTENTION, the automated task should go to the Account Owner for Practice Pay Rxs and to the MSC Owner for Patient Pay Rxs. If the relevant owner is missing, the task should go to csharp@evitalin.com instead of being skipped.

Why a code change: The stage had a single global "Task Assigned To" setting (MSC Owner or Account Owner), so it couldn't vary by pay type.

What changed (bista_menmd_customization):

  • models/bs_prescription_stages.py
    • New Based on Pay Type option on z_task_assigned_to.
    • New field z_account_owner_pay_type (default Practice Pay). Rxs with this pay type route to the Account Owner, and all others route to the MSC Owner.
    • New field z_task_fallback_user_id. When the Rx has no owner for the resolved assignment, this user gets the task. If it's left empty, no task is created, which is the existing behavior.
    • New helper _get_task_owner_field(pay_type). It returns the Rx owner field (z_owner_id or z_salesperson_id) to assign the task to, which keeps the routing logic in one place.
  • models/prescription.py
    • _handle_stage_changes(): resolves the assignee through the helper and applies the fallback user. It takes a new pay_type param, so the routing uses the pending pay type when the stage and pay type change in the same save.
    • write() owner-change branch: uses the helper to decide which owner change creates a new task. The fallback isn't used here, so clearing an owner doesn't send the fallback user a duplicate task.
  • views/bs_prescription_stages.xml: new fields on the form, shown only when relevant, and on the tree view as optional hidden columns.

Behavior: Stages set to MSC Owner or Account Owner work exactly as before. The stage logic doesn't check stage names, so any stage can use Based on Pay Type. Existing open tasks aren't touched, so the change applies going forward only.

Deploy: -u bista_menmd_customization is needed for the new fields. No data file is included, since NEEDS ATTENTION already exists on UAT/prod and is configured in the UI.

Post-deploy config (Sales > Configuration > Rx Stages > NEEDS ATTENTION):

  1. Task Assigned To: Based on Pay Type
  2. Assign to Account Owner if pay type is: Practice Pay
  3. Fallback Task Assignee: csharp@evitalin.com

Known limitation (existing behavior, out of scope): Owner-change tasks only fire when the owner is written directly on the Rx. Changing the Account Owner at the provider level doesn't create a new task on existing Rxs.

Contact brief

The NEEDS ATTENTION task assignment has been updated. When an Rx moves into NEEDS ATTENTION:

  • Practice Pay: the task goes to the Account Owner.
  • Patient Pay: the task goes to the MSC Owner.
  • If that owner isn't set on the Rx, the task goes to csharp@evitalin.com so nothing gets missed. Before, these tasks were silently skipped.

The change applies going forward only. Existing open NEEDS ATTENTION tasks keep their current assignee.

If the owner is changed directly on an Rx that's already in NEEDS ATTENTION, the new owner gets a task. However, changing the Account Owner on the provider or account doesn't update the Rxs or reassign their open tasks. If you'd like that to happen automatically, let us know and we can scope it as a separate request.

How to test

Setup: Use two users besides the fallback user: User A as the Account Owner and User B as the MSC Owner. Start with Rxs that are not in NEEDS ATTENTION or Sent To Lab. After each step, check the Rx chatter under Planned Activities for the assignee. Due Days is 0, so tasks should be due today.

#StepsExpected
1Practice Pay, both owners set, move to NEEDS ATTENTIONTask to Account Owner (User A)
2Patient Pay, both owners set, move to NEEDS ATTENTIONTask to MSC Owner (User B)
3Practice Pay, no Account Owner (MSC Owner set), move to NEEDS ATTENTIONTask to fallback user
4Patient Pay, no MSC Owner (Account Owner set), move to NEEDS ATTENTIONTask to fallback user
5aPractice Pay Rx already in NEEDS ATTENTION: change Account Owner on the RxNew task for new Account Owner
5bSame Rx: change MSC Owner on the RxNo new task
5cPatient Pay Rx already in NEEDS ATTENTION: change MSC Owner on the RxNew task for new MSC Owner
5dSame Rx: change Account Owner on the RxNo new task
6Patient Pay Rx, both owners set: change pay type to Practice Pay and stage to NEEDS ATTENTION in one saveTask to Account Owner
7Move an Rx into another task-generating stage set to MSC Owner or Account OwnerAssigns as before