Add Pinwheel Clause support for zone-based encounters in route groups
Allows each sub-zone within a route group to have its own independent encounter when the Pinwheel Clause rule is enabled (default on), instead of the entire group sharing a single encounter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,15 +50,30 @@ async def create_encounter(
|
||||
detail="Cannot create encounter on a parent route. Use a child route instead.",
|
||||
)
|
||||
|
||||
# If this route has a parent, check if any sibling already has an encounter
|
||||
# If this route has a parent, check if sibling already has an encounter
|
||||
if route.parent_route_id is not None:
|
||||
# Get all sibling route IDs (routes with same parent, including this one)
|
||||
# Get all sibling routes (routes with same parent, including this one)
|
||||
siblings_result = await session.execute(
|
||||
select(Route.id).where(Route.parent_route_id == route.parent_route_id)
|
||||
select(Route).where(Route.parent_route_id == route.parent_route_id)
|
||||
)
|
||||
sibling_ids = [r for r in siblings_result.scalars().all()]
|
||||
siblings = siblings_result.scalars().all()
|
||||
|
||||
# Check if any sibling already has an encounter in this run
|
||||
# Determine which siblings to check based on pinwheel clause
|
||||
pinwheel_on = run.rules.get("pinwheelClause", True) if run.rules else True
|
||||
any_has_zone = any(s.pinwheel_zone is not None for s in siblings)
|
||||
|
||||
if pinwheel_on and any_has_zone:
|
||||
# Zone-aware: only check siblings in the same zone (null treated as 0)
|
||||
my_zone = route.pinwheel_zone if route.pinwheel_zone is not None else 0
|
||||
sibling_ids = [
|
||||
s.id for s in siblings
|
||||
if (s.pinwheel_zone if s.pinwheel_zone is not None else 0) == my_zone
|
||||
]
|
||||
else:
|
||||
# No pinwheel clause or no zones defined: all siblings share
|
||||
sibling_ids = [s.id for s in siblings]
|
||||
|
||||
# Check if any relevant sibling already has an encounter in this run
|
||||
existing_encounter = await session.execute(
|
||||
select(Encounter)
|
||||
.where(
|
||||
|
||||
Reference in New Issue
Block a user