Skip to main content

Facility Service — Service Overview

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · 03 platform-services · 02 DDD

1. Purpose

The facility-service is the authoritative registry of physical and organisational structure within the Ghasi-eHealth platform. It owns the organisation hierarchy graph (HierarchyNode + HierarchyEdge + HierarchyProfile) and the facility operational overlay (Location, Bed, ResourceCatalogItem, LocationHours) that every clinical, scheduling, licensing, billing, and access-policy service depends on.

2. Bounded Context

Facility & Hierarchy — classified as Supporting. It is not a clinical domain itself, but it is a shared-kernel prerequisite for Licensing, Access Policy, Registration, Scheduling, Orders, Billing, and Population Health. The context consolidates two legacy modules — facility-management and hierarchy — into a single bounded context with one aggregate model, one API surface, and one event stream.

3. Responsibilities

AreaWhat facility-service Owns
Hierarchy graphHierarchyNode (moph, region, district, hospital, clinic, department, ward, virtual-clinic), HierarchyEdge (contains/manages/refers-to), DAG invariants
Hierarchy profilesPer-tenant configurable schema (allowed node types, depth, required children); seeded profiles for AFG_MOPH, UAE_DOH, PRIVATE_HOSPITAL, CLINIC_SIMPLE, TELEMEDICINE
Facility locationsLocation rows anchored to exactly one HierarchyNode; operational hours; time zone + locale defaults
Bed managementBed aggregate with bed class, status, isolation capability, housekeeping status; single-active-encounter invariant
Resource catalogRooms and equipment consumable by scheduling-service
Traversal APIsSub-tree, ancestors, context-by-provider, inheritance chain (for Licensing/Access Policy)
Provider node membershipProviderNodeMembership — linkage from provider → node with effective-from/to; consumed by access-policy
Facility definition import/exportSnapshot artefact for multi-site deployments
FHIR canonical projectionOrganization, Location, HealthcareService

4. Non-Responsibilities

AreaOwnerWhy Not facility-service
Clinician identity & credentialsprovider-directory-serviceProviders are an identity concern; facility only stores node-membership edges
License/entitlement policyLicensing Service (inside platform-admin)Facility publishes node context; Licensing resolves entitlement at that node
RBAC/ABAC evaluationtenant-service + access-policyFacility publishes scope context only
Patient identityregistration-serviceEncounters link location → patient, not the other way
Appointment bookingscheduling-serviceScheduling consumes the resource catalog and slot hours

5. Dependencies

5.1 Upstream

DependencyPatternPurpose
tenant-serviceShared kernel (TenantId)Tenant isolation; tenant.created event seeds default hierarchy profile
identity-serviceCF (JWT validation)Admin APIs validate JWTs issued by identity-service
Access Policy (platform-admin)RPCEvery write authorised via POST /internal/access/evaluate

5.2 Downstream Consumers

ConsumerPatternWhat They Consume
Licensing (platform-admin)Event + RPCHierarchy ancestor chain for resolveEffectiveLicenses(nodeId)
Access Policy (platform-admin)Event + RPCNode subtree + provider memberships for scope decisions
scheduling-serviceEvent + RPCLocation, hours, resource catalog; bed / resource availability seeds
registration-serviceEvent + RPCLocation reference on Encounter.location
orders/laboratory/radiologyEvent + RPCPerforming-location resolution
billing-serviceEventService-line + bed-class reporting dimensions
interop-service (FHIR)EventOrganization, Location publication to FHIR gateway
population-health-serviceEventHierarchy dimensions for HMIS aggregation

5.3 Events Consumed

EventProducerPurpose
tenant.tenant.created.v1tenant-serviceSeed default hierarchy profile + root org node for new tenant
tenant.tenant.archived.v1tenant-serviceCascade-deactivate facility nodes; preserve historical data
provider_directory.practitioner.created.v1provider-directory-serviceAllow subsequent ProviderNodeMembership writes

6. Slice Involvement

SliceScopeMilestone
S0 — FoundationHierarchy graph CRUD, profiles, Location + Bed CRUD, ancestor/subtree APIs, FHIR LocationM0
S1 — OperationalResource catalog, location hours, holiday calendars, bed status stream, provider membershipsM1
S2 — InteropFHIR Organization/HealthcareService; HL7 v2 PV1 location alignmentM2
S4 — EnterpriseFacility definition import/export, cross-site federation, accreditation registry bridgesM3

7. Architectural Freeze Points

FreezeWhat Is FrozenBy
F03HierarchyNodeId, LocationId, BedId, ResourceId, ProfileId branded typesEnd of M0
F01EventEnvelope conformance for all facility.* eventsEnd of M0
F04Hierarchy DAG invariant: contains edges may not form cyclesEnd of M0

8. Readiness Levels

LevelTarget MilestoneCapabilities
L2M0Hierarchy graph + Location + Bed operational, basic monitoring
L3M1Provider membership live, cached context lookups p99 ≤ 20ms, contract tests green
L4M3Federated registries, import/export at scale, chaos-tested

9. Architecture Diagram

10. Key Design Decisions

  1. One service owns both the structural graph and the operational overlay. Legacy hierarchy and facility-management merged. Locations always anchor to exactly one HierarchyNode (no orphan locations).
  2. Graph is a DAG, not a strict tree. A node may have multiple parents (refers-to, manages). contains edges are the primary ownership edge and must not form cycles.
  3. HierarchyProfile drives validation, not code. Country / deployment variations (AFG MoPH vs UAE DoH vs private clinic) are configuration.
  4. Redis-cached context lookup is the hot path. Every downstream service calls GET /internal/nodes/:id/context; p99 must stay ≤ 20ms. Event-driven invalidation within 30s.
  5. License + access checks are delegated, not local. facility-service never evaluates entitlement; it publishes node context and ancestors for Licensing/Access Policy to resolve.
  6. FHIR is a projection, not the store. Internal domain uses the DAG; FHIR Organization/Location is generated from it.

11. Source Reconciliation

The two legacy modules are merged per the following rules:

ConcernLegacy modulePost-merge owner
HierarchyNode / Edge / Profile CRUDhierarchyfacility-serviceHierarchy aggregate
Location + Bed + Hours operational metadatafacility-managementfacility-serviceLocation and Bed aggregates anchored to HierarchyNode
Resource catalogfacility-managementfacility-serviceResource aggregate
Provider node membershiphierarchyfacility-service — shared-kernel read model for access-policy
FHIR Organization/Locationfacility-managementfacility-service infrastructure projection

Legacy FR prefixes (FR-FAC-*, FR-HIER-*) are preserved in EPICS.md / USER_STORIES.md under the "Legacy ref" column.

12. Open Questions

  • Are national accreditation registries (AFG HMIS facility codes) a first-class field or metadata JSON? TBD.
  • Cross-tenant hierarchy federation (shared regional nodes) — defer to M3+.