Skip to main content

Frozen Taxonomy Registry

The frozen taxonomy registry is a read-only, in-memory entity index loaded from the PostgreSQL-backed taxonomy at application startup. It provides constant-time lookups for entity resolution, relationship validation, and allowlist filtering. The registry is "frozen" because it represents a point-in-time snapshot of the hospital's entity inventory: it does not change during system operation and is refreshed only when a new taxonomy version is published (or the taxonomy is re-extracted).

Hub/Detail Reclassification (2026-03-09)

The original 8-type page classification was replaced with a binary hub/detail classification. Hub pages (a few dozen per hospital) are auto-detected by an LLM classifier. Configuration files no longer contain department, doctor or golden-page lists: the database is the sole source of truth.

What Problem Does It Solve?​

Without the registry, the extraction pipeline would accept any string that matches a doctor-name pattern as a valid doctor, any department-like pattern as a real department, and any relationship between them as plausible. This produces a noisy graph full of phantom entities: job titles parsed as doctor names, section headers stored as departments, body parts classified as conditions.

The registry solves this by providing an authoritative inventory of known entities scraped from the hospital's own website. During extraction, every entity is checked against this inventory:

  • Known entities are accepted and normalised to their canonical names.
  • Unknown entities are either rejected (doctors, departments) or flagged for downstream LLM validation (conditions, treatments, examinations).

Package Architecture​

The taxonomy package has nine modules, each with one responsibility:

ModulePurpose
Public interfaceExports the frozen models, the scrape result and the registry functions
ModelsImmutable objects for doctors, departments, conditions, treatments, examinations, consultation schedules and the overall scrape result
RegistryThe registry class and its singleton lifecycle (get, initialise, clear)
Allowlist filterFilters extraction results against the registry
PersistenceSaves and loads the scrape result in PostgreSQL
Scraper baseAn abstract asynchronous HTTP fetcher
Hospital scraperThe hospital-specific HTML parser
Golden-page configurationA description of golden page sets (historically from configuration; hub pages are now auto-discovered by the LLM classifier)
Golden-page seederMerges three knowledge sources and seeds the taxonomy

Data Models​

All models are immutable (frozen) to guarantee they cannot change after loading:

ModelKey Fields
Doctorname, departments, specialties, campuses, source page and site
Departmentcanonical name, aliases, campuses, domain group, conditions, treatments, examinations
Conditioncanonical name, aliases, category
Treatmentcanonical name, aliases, category
Examinationcanonical name, aliases, category
Consultation scheduledoctor, department, time slots (day, period, type), status, campus contacts
Scrape resultLists of all entity types plus schedules, scrape time and source sites

Constant-Time Lookup Indexes​

The registry builds ten lookup indexes once, at construction:

IndexKeyValueUsed For
Doctor namesoriginal case(set)Listing known doctors
Doctor names, lower-caselower-case(set)Known-doctor check
Department aliasesaliascanonical nameDepartment resolution
Condition aliasesaliascanonical nameCondition resolution
Treatment aliasesaliascanonical nameTreatment resolution
Examination aliasesaliascanonical nameExamination resolution
Department to conditionsdepartmentcondition namesHANDLES validation
Department to treatmentsdepartmenttreatment namesOFFERS validation
Department to examinationsdepartmentexamination namesPERFORMS validation
Departments by keydepartmentthe full department objectDepartment lookup

All lookups are case-insensitive.

Core Capabilities​

The registry offers these operations:

  • check in constant time whether an entity of a given type exists in the taxonomy;
  • resolve an alias to its canonical name (returning nothing if unknown);
  • a dedicated doctor check, case-insensitive and tolerant of the "Dr." prefix;
  • look up a full department object by name or alias;
  • validate a relationship against taxonomy data and the knowledge maps;
  • report entity counts by type.

Dependency Injection​

The knowledge maps the registry depends on can be injected at construction. By default the registry loads the general medical knowledge maps itself; in unit tests, custom maps can be supplied instead, so tests do not need to import the whole knowledge package.

Singleton Lifecycle​

The registry is a singleton because it represents a global, read-only resource. It can be initialised asynchronously from the database, or synchronously from a scrape result (for tests and scripts); it can be fetched from anywhere (returning nothing if not initialised) and reset (for testing only).

It is initialised once at application startup and refreshed when the taxonomy is re-scraped by an administrator or a new version is published.

Stored Data​

The taxonomy is stored in PostgreSQL in three logical stores.

Taxonomy entities​

The frozen entity allowlist. Each record has the owning tenant, an entity type (doctor, department, condition, treatment or examination), a canonical name, a list of aliases, descriptive metadata (departments and specialties for doctors, domain group for departments), the source page and site, and an active flag. A uniqueness rule on tenant, type and canonical name makes updates idempotent for non-doctor entities.

Taxonomy relationships​

Scraped department-to-entity maps. Each record has the tenant, the source and target names and types (for example "Cardiologie" department to "Hartfalen" condition), the relationship type (handles, offers, performs, or a works-in schedule) and metadata (schedule slots and campus contacts for the schedule type).

Unknown entities​

A human review queue for entities detected during ingestion but not found in the taxonomy: the name, the detected type, a status (pending, approved or rejected), the canonical name it was resolved to if approved, and the content snippet where it was found.

Allowlist Filter​

The allowlist filter validates extraction results against the registry using a dual-mode filtering strategy:

Entity Filtering Modes​

ModeEntity TypesBehaviour
Passthroughcampus, hospital, facilityAlways kept, no taxonomy check
Strictdoctor, departmentMust exist in the taxonomy; unknown entities are rejected and recorded
Relaxedcondition, treatment, examination, serviceKept even without a taxonomy match; canonical name applied if found

Relationship Filtering (Three Gates)​

  1. Source-type gating. Works-in and works-at-campus relationships require the source page to be a golden (hub) source; handles, offers and performs require an authoritative source.
  2. Endpoint survival. Both the source and target entity names must be among the kept entities.
  3. Taxonomy validation. The registry checks the relationship against frozen taxonomy data and the fallback domain knowledge maps.

Scraping Flow​

The scraper fetches HTML from hub pages (auto-detected by the LLM classifier from crawled content), parses doctors, departments, conditions, treatments, examinations and consultation schedules, then deduplicates across both sites. The persistence layer uses a full-replacement strategy: existing entities for the tenant are removed and the new ones inserted, so the taxonomy always reflects the latest extraction. The database is the sole source of truth.

Integration Points​

The registry integrates at three pipeline stages:

  1. Extraction time. At the end of medical entity extraction, if a registry is loaded, the allowlist filter is applied to the extraction result, taking the source page and its page type into account.
  2. Graph seeding. The golden-page seeder reads the registry to build an extraction result that combines scraped entities with domain knowledge maps. See Seeding Pipeline.
  3. Query-time resolution. A search-query resolver uses alias maps built from the hospital configuration, enriched by registry data when available, so that patient-friendly terms ("hartdokter") resolve to canonical department names ("Cardiologie"). It is used by query entity extraction, by query enrichment with taxonomy terms, and by intent routing based on entity type.

Loading from Published Data (SP-5)​

Loading from a published version (added in SP-5) is the production initialization path. Instead of the older scrape-result format, the registry reads the versioned published entities and relationships created by the Draft/Publish System, for the latest version by default or for a chosen one.

When loading, the registry:

  1. Entities. Groups rows by entity type and converts them into doctor, department, condition, treatment and examination objects.
  2. Aliases. Unpacks the stored alias lists to populate the alias maps.
  3. Relationships. Converts handles, offers and performs rows into the three department-to-entity indexes.
  4. Schedules. Parses schedule relationships and their metadata into consultation schedule objects.

Version-Check Cache Invalidation​

The running registry checks for a newly published version about once a minute and reloads when a newer one exists. After every publish or rollback, the publish service forces an immediate rebuild, so the change is live in search without waiting for the next check.

Backward Compatibility​

The scrape-result-based initialization path remains functional. It is used for:

  • Unit tests, which inject a scrape result without a database;
  • Legacy scripts that predate SP-5;
  • Development, for quick local initialization without a published version.

When a hospital has no published version yet (for example a new tenant mid-setup), the registry falls back to loading the draft taxonomy directly until the first publish completes.

Migration Path

Hospitals initialised through the earlier scrape-and-seed steps before SP-5 continue to work without modification. The first explicit publish creates the published snapshot and switches the registry to the published-version path.

References​