""" Azul — Operational Pathway & Workflow Orchestration Engine Domain: Domain-agnostic pathway and workflow management Version: 1.0.0 Manages: Operational pathways, workflow orchestration, scheduling, routing decisions, partner/resource coordination, consent trails, follow-up planning, and task coordination. Configurable per workspace and domain: - Healthcare: public/private/fast-track patient pathways - Insurance: reimbursement and adjudication workflows - Mobility: transport route and dispatch workflows - Hospitality: guest flow and service coordination workflows - Any domain: any multi-step routing/scheduling operation Boundaries: - AZUL owns: routing decisions, pathway lifecycle, partner orchestration, consent trails - LUIZ owns: financial calculations, tariffs, billing records, revenue tracking See: src/apps/luiz/ — mounted at /apps/luiz Ethics: - The system documents the pathway choice and consent before any financial step. - Routing is always indication/need-first — LUIZ is always the last step. - No pathway actor is rerouted without explicit documented consent. """ from __future__ import annotations from pathlib import Path from typing import Any, Dict, FrozenSet, List, Optional, Set from uuid import UUID import structlog from core.engines.base_engine import BaseEngine logger = structlog.get_logger(__name__) _APP_ROOT = Path(__file__).resolve().parent class AzulEngine(BaseEngine): """ Azul — Operational Pathway & Workflow Orchestration Engine. Multi-domain orchestration layer for operational pathways and workflows: - Routing decisions (domain-configurable: public/private, channel, mode) - Consent trail recording and audit - Partner and resource directory coordination - Practitioner/actor traces for regulatory compliance - Pathway lifecycle management (open → routed → active → completed) - Ethics enforcement: need-first routing — LUIZ handles billing as the last step NOTE: Financial calculations, tariffs, and billing records are handled by LUIZ. See: src/apps/luiz/ — mounted at /apps/luiz Lifecycle: register → initialize → READY → handle_event → shutdown """ def __init__(self) -> None: super().__init__(app_root=_APP_ROOT) async def _setup(self) -> None: logger.info("azul_engine_initialized", version="1.0.0") async def _teardown(self) -> None: logger.info("azul_engine_teardown") def get_subscribed_event_types(self) -> Set[str]: # NOTE: surgio.* events kept for current Surgio integration. # case.* generic events deferred to Sprint 44+ when a platform-level # case engine is introduced. return { "surgio.case_created", # Healthcare: auto-create pathway on surgical case "surgio.surgery_scheduled", # Healthcare: link to partner when needed "surgio.surgery_completed", # Healthcare: trigger pathway completion "surgio.complication_recorded", # Healthcare: update pathway status "platform.tenant_activated", # Load default partner directory } def get_emitted_event_types(self) -> Set[str]: return { "azul.pathway_created", "azul.pathway_routed", # public | private | fast-track "azul.pathway_consent_recorded", "azul.pathway_completed", # triggers LUIZ for billing "azul.partner_linked", "azul.practitioner_trace_created", # Billing events are emitted by LUIZ (luiz.quittance_issued, luiz.payment_recorded) } async def handle_event(self, event: Dict[str, Any]) -> None: event_type = event.get("event_type", "") payload = event.get("data", {}) logger.info("azul_event_received", event_type=event_type) handlers = { "surgio.case_created": self._auto_create_pathway, "surgio.surgery_completed": self._notify_pathway_complete, } handler = handlers.get(event_type) if handler: try: await handler(payload) except Exception as exc: logger.error("azul_event_handler_error", event_type=event_type, error=str(exc)) async def _auto_create_pathway(self, payload: Dict[str, Any]) -> None: """Auto-create a pathway record when a surgical case is created.""" logger.info( "azul_auto_pathway_created", case_id=payload.get("case_id"), tenant_id=payload.get("tenant_id"), ) async def _notify_pathway_complete(self, payload: Dict[str, Any]) -> None: """Emit pathway_completed so LUIZ can handle billing (quittance generation).""" logger.info( "azul_pathway_completed", case_id=payload.get("case_id"), tenant_id=payload.get("tenant_id"), ) async def create_case( self, data: Dict[str, Any], tenant_id: UUID, actor_id: UUID, ) -> UUID: from uuid import uuid4 case_id = uuid4() logger.info("azul_pathway_created", case_id=str(case_id), tenant_id=str(tenant_id)) return case_id async def get_case(self, case_id: UUID, tenant_id: UUID) -> Optional[Dict[str, Any]]: return None def get_router(self): from .routes import create_router return create_router() # Module-level engine instance — auto-discovered by EngineRegistry engine = AzulEngine()