Conversation
aegis301
approved these changes
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scaffold
Location-tree data loaded at backend startup from JSON files in a configurable directory.
Environment
*.jsonfiles. If unset, scaffold loading is skipped.CHECK,MERGE,FORCE. Parsed from env (case-insensitive); invalid values fall back toCHECK.JSON format
Each file may be a single root object or a list of root objects. Root objects have:
name,type(e.g.HOSPITAL,CLINIC,WARD,ROOM,BED,TEAM,PRACTICE,OTHER)children(array of same shape)organization_ids(for HOSPITAL, CLINIC, PRACTICE, TEAM)All
*.jsonfiles in the directory are loaded, merged into one list of root items, and imported in a single transaction.Strategies
CHECK (default)
MERGE
title,kind,parent_idand reused).FORCE
Before deleting locations:
Fallback clinic for existing patients
If any patient has a
clinic_id, a “FALLBACK_CLINIC” is created (root CLINIC) and linked to the organizationglobal. All such patients are moved to this fallback clinic so they are not left without a clinic. On every scaffold load (restart), if that fallback node still exists but no patient has it as clinic, and no user has it as root location, and no task has it as assignee team, and no patient has it in teams, the fallback node is deleted.Personal location nodes are not deleted
Location nodes created for users without an attached organization (title
"{username}'s Organization", root, no row inlocation_organizations) are preserved. Only other scaffold/organization locations are removed.User root-location links (
user_root_locations) are removed only for locations that are being deleted; links to preserved personal locations stay.Patient assignments (locations, teams), task assignee team, and then
location_organizationsand the non-preserved location nodes are cleared. Preserved nodes and the fallback clinic (if created) are kept.The merged JSON payload is imported as in MERGE.
Personal location nodes
When a user has no organization attached, the backend creates a single root location for them: title
"{username}'s Organization", kind CLINIC, with nolocation_organizationsrow. These nodes are considered personal and are never deleted by scaffold FORCE, so user access is preserved.Reinitialization check (MERGE / FORCE)
A hash of the scaffold directory (file names, mtimes, sizes, and contents) is computed in memory and stored in the database after a successful import (table
scaffold_import_state, keydirectory_hash). No files are written to the scaffold directory. On the next run, the backend compares the current directory hash with the stored value; if they match, the 120-second reinitialization wait is skipped.