Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt

Use this file to discover all available pages before exploring further.

Module: Practice Management (PM-16)
Last Updated: 2026-02-23

Overview

This guide covers configuration, permissions, and operational management for the Patient Statement Billing module.

Quick Reference

I need to…PatternLocation
Configure billing permissionsRole-to-permission mapping for statement operationsPermission Configuration
Automate statement runsScheduled cron trigger to run-statement-cycleScheduling (Cron)
Run statements manuallyTrigger on-demand statement cycleRun Types

Permission Configuration

Permission Keys

KeyCategoryDescription
pm.statements.viewviewView statement runs and delivery history
pm.statements.generatecreateTrigger statement generation cycles
pm.statements.manageadminFull management of statement runs
pm.payment_plans.viewviewView payment plans
pm.payment_plans.createcreateCreate new payment plans
pm.payment_plans.editeditModify existing payment plans
pm.payment_plans.deletedeleteDelete payment plans
pm.financial_assistance.viewviewView financial assistance applications
pm.financial_assistance.createcreateSubmit new applications
pm.financial_assistance.reviewapproveReview (approve/deny) applications
RolePermissions
Org AdminAll (auto-granted)
Billing Staffstatements.view/generate, payment_plans.*, financial_assistance.view/create
CollectionsAll billing + financial_assistance.review
Front Deskstatements.view, payment_plans.view, financial_assistance.view

Statement Run Configuration

Run Types

  • On Demand: Manually triggered by staff for immediate statement generation.
  • Scheduled: Configured to run at specific intervals (requires cron setup).
  • Cycle End: Triggered at the end of a billing cycle.

Scheduling (Cron)

Statement runs can be automated via the Supabase dashboard cron or pg_cron:
-- Example: Run monthly on the 1st at 6:00 AM UTC
SELECT cron.schedule(
  'monthly-statements',
  '0 6 1 * *',
  $$SELECT net.http_post(
    'https://<project-ref>.supabase.co/functions/v1/run-statement-cycle',
    '{"organization_id": "<org-id>", "run_type": "scheduled"}'::jsonb,
    '{}'::jsonb,
    '{"Content-Type": "application/json"}'::jsonb
  )$$
);
⚠️ Security: Do not embed secrets in cron payloads. The invoked function should retrieve privileged credentials from secure server-side secret storage (environment secrets/secret manager) at runtime.

Edge Function: run-statement-cycle

  • Location: supabase/functions/run-statement-cycle/index.ts
  • Auth: Requires valid JWT with org access, or service role for cron invocations.
  • Parameters: organization_id (required), run_type, date_range_start, date_range_end, minimum_balance.

Delivery Channels

ChannelConfiguration Required
PrintNone (generates PDF for download)
EmailPatient must have email on file; org email provider (Entra/Gmail) must be configured
PortalPatient must have portal access (PM-12)
Text/SMSSMS provider configured in CE module settings

Database Tables

TablePurpose
pm_statement_runsTracks statement generation cycles
pm_statement_deliveriesAppend-only delivery audit log
pm_payment_plansPatient payment plan agreements
pm_financial_assistance_applicationsCharity care / sliding scale applications

RLS Policies

  • SELECT/INSERT/UPDATE: Enforced via pm_has_org_access(organization_id, auth.uid())
  • DELETE: Restricted to pf_is_org_admin(auth.uid(), organization_id)
  • pm_statement_deliveries: Append-only — SELECT and INSERT only; no UPDATE or DELETE

Data Retention

  • Statement deliveries are append-only and cannot be modified or deleted by any user role.
  • Statement runs and their linked statements follow standard PM data retention policies.

Monitoring

Edge Function Logs

Monitor the run-statement-cycle function via:

Key Metrics

  • Statements generated per run
  • Delivery success/failure rates
  • Average statement generation time
  • Payment plan completion rates
  • Financial assistance approval rates

Troubleshooting

IssueResolution
Statement run failsCheck Edge Function logs for errors. Common causes: missing patient data, DB connection issues.
Email deliveries failingVerify org email provider (Entra/Gmail) sender configuration and credentials. Check send-pending-notifications logs.
Permission denied errorsVerify user has correct role assignments in Organization Settings.
Statement amounts incorrectCheck pm_patient_statements data; verify charge capture (PM-07) is complete for the billing period.