"""Decision themes for the implementation plan. HAND-AUTHORED: edit this file, then run build_decisions.py.

Every open decision in section 18.3 of the domain specifications belongs to exactly one theme here;
build_decisions.py fails if one is missing, duplicated or unknown. Resolved decisions are excluded automatically.

lead     = the single role proposed to drive the theme to a decision (the specifications name several owners per decision)
proceed  = whether build can start on the working position before the decision is made: 'No', 'Partly' or 'Yes'
cost     = cost of proceeding on the working position if the decision later goes the other way: 'High', 'Medium' or 'Low'
position = the working position the specifications apply today
cost_text= what would have to be redone, and why the rating
ids      = decisions, written as '<DOMAIN ABBREV>-<NNN>' and expanded to DEC-<ABBREV>-<NNN>
"""

THEMES = [
    dict(id='T01', title='Technology stack, hosting and operations model',
         lead='CIO with the Enterprise Architecture Board', proceed='No', cost='High',
         position='None that can be built on. The specifications state requirements and constraints (organization-controlled hosting, no mandatory vendor control plane, replaceable components) but do not choose the runtime, database, event broker, gateway, identity provider, hosting location or security-operations model.',
         cost_text='There is no working position to proceed on: the first slice cannot be built without these choices. Changing the database, broker or identity provider after services exist is a rewrite of the affected services and a re-run of every gate passed. The hosting and disaster-recovery locations also fix what ACC-006 can demonstrate.',
         ids='ISE-003, ISE-002, ISE-001, ISE-009, ESS-005, ESS-008, ANL-004'),
    dict(id='T02', title='Patient identity policy and MPI governance',
         lead='HIM and registration governance', proceed='No', cost='High',
         position='Domain 1 owns the patient index and registration; Domain 10 owns workforce and service identity; Domain 7 presents portal identity linking. Identifier formats, national identifier handling, matching attributes, weights and thresholds, merge authority and the stewardship roster are not set; automatic merge is off by default.',
         cost_text='Ownership can proceed on the working position at low cost. The identity policy cannot: identifier formats and assigning authorities are written into every patient, encounter, order and charge from the first registration, and matching thresholds must be validated on local data before ACC-004 can be signed. Changing identifier formats after go-live means re-issuing identifiers and re-linking records in every domain and external system.',
         ids='ADM-002, ADM-001, ADM-003, ESS-001, HIM-003, PEX-001'),
    dict(id='T03', title='Terminology strategy and data governance ownership',
         lead='Data Governance Council with Clinical Informatics', proceed='Partly', cost='High',
         position='Domain 10 owns the terminology service, code systems, value sets, master and reference data; Domain 9 owns guideline concept mapping; Domain 6 owns encounter coding; Domain 8 applies analytical data-quality controls. Which code systems are required, their licensing, local catalogues and the research data model are not chosen.',
         cost_text='The service and the ownership split can be built on the working position. The choice of code systems cannot be deferred past the first coded clinical data: problems, allergies, orders, results and medication are all bound to it, and changing a code system later means remapping stored clinical data with steward review and re-validating every decision-support rule and pathway that uses it. Licensing can also take time to obtain. The ownership allocations are low cost to change.',
         ids='ESS-012, ESS-004, CLI-004, EBP-008, HIM-016, ESS-020, ESS-015, ANL-003'),
    dict(id='T04', title='Platform, shared-service and task boundaries',
         lead='Enterprise Architecture Board', proceed='Yes', cost='Medium',
         position='Domain 2 owns transport, gateways, event backbone, platform security controls, observability, backup and release; Domain 10 owns identity records and grants, authorization decisions, audit, notification, workflow and task capability, document service and configuration governance. Domains keep their own workflow state and call the shared task service for work items.',
         cost_text='A different split moves modules between two teams and changes which service exposes a contract, but not what is required. The cost grows with every consumer built against a contract: after stage 1 each change means versioning an interface that all later slices use. Deciding where task state and configuration content live is the part most worth settling early, because every domain copies the pattern.',
         ids='ESS-011, ESS-007, ISE-007, ISE-008, ESS-014, ESS-016, ESS-017, ESS-013, ADM-015, CLI-007, HIM-004, EBP-019, EBP-023'),
    dict(id='T05', title='Service tiers, recovery targets and failure behaviour',
         lead='Clinical governance with the CIO', proceed='Partly', cost='High',
         position='The PRS tier scheme (Tier 1 to 4) is used in preference to the Architecture scheme (Tier 0 to 3). Each domain proposes a tier for its services. Numeric availability, RTO and RPO exist only as PRS proposals for the top two tiers. Shared services fail closed, with cached decisions for Tier 1 reads, as a proposal pending hazard analysis.',
         cost_text='Design can start on the proposed tiers, but a service built for a lower tier than it is finally given needs its deployment topology, data replication and downtime procedure redone, which is costly once it is live. No recovery gate (ACC-006) or downtime rehearsal (ACC-007) can be signed without approved numbers, so the scheme and the Tier 1 and 2 targets are needed before the stage 2 gate. How shared services behave when unreachable, and how a network-isolated ward authenticates, are safety decisions that the working position only proposes.',
         ids='ISE-005, ESS-018, ESS-006, ADM-014, ANC-008, CLI-012, EBP-017, FIN-011, HIM-014, PEX-009, ANL-010'),
    dict(id='T06', title='Consent model and privacy segmentation',
         lead='Security and Privacy Office with legal advice', proceed='Partly', cost='High',
         position='Domain 10 owns the consent directive and the policy decision; Domain 1 captures references at registration; Domain 6 keeps consent evidence and disclosure restrictions; Domain 7 presents preferences. The sensitive categories, legal bases, labels, emergency exceptions, effect of withdrawal, representative-access rules and the basis for secondary use are not defined.',
         cost_text='The mechanism (directive, labels, policy decision) can be built on the working position. The content cannot be guessed: a wrong model either exposes sensitive data or blocks care, both of which are safety and legal failures. If categories or labels change after clinical data exists, stored data has to be relabelled and every access decision re-tested. The consent model is needed before consent is first captured (stage 2) and the segmentation rules before the clinical record goes live (stage 3).',
         ids='ESS-009, ESS-002, ADM-013, CLI-008, HIM-010, HIM-011, HIM-015, PEX-002, ANL-007'),
    dict(id='T07', title='Interoperability profiles and jurisdiction requirements',
         lead='Integration architect with data governance and legal', proceed='Partly', cost='Medium',
         position='HL7 v2, FHIR, DICOM and IHE are supported behind the integration layer with versions and profiles left configurable. The Indonesia deployment profile is treated as a configurable package whose mandatory datasets, API versions and certification criteria are to be confirmed. Third-party application access follows a standard authorization profile to be selected.',
         cost_text='Adapters are isolated behind the integration layer, so a different FHIR release or message version is rework of profiles and conformance tests, not of domain services. The cost rises if a national profile turns out to require data elements that registration or the clinical record did not capture, because that reaches back into screens, validation and migrated data. Certification lead time is outside the project\'s control. The administrative profile is needed before the first external ADT exchange (stage 2).',
         ids='ISE-004, ISE-010, HIM-018, ADM-006, ESS-010, PEX-007, FIN-009, EBP-016, ANL-012'),
    dict(id='T08', title='Encounter model and patient-flow boundaries',
         lead='Hospital operations with the Enterprise Architecture Board', proceed='Partly', cost='Medium',
         position='The PRS encounter states are used, with "transferred" and "corrected" recorded as history entries and On leave and Closed added. Emergency-to-inpatient admission, closure criteria, the encounter validation policy and isolation as a bed state are configurable with proposed defaults. Domain 1 owns real-time flow boards and resource calendars; Domain 8 owns aggregated reporting; Domain 4 owns imaging and theatre lists; Domain 7 owns patient-facing reminders.',
         cost_text='The encounter is the reference every order, result, document and charge is validated against. Changing its states or whether an emergency admission continues or opens a new encounter after downstream domains are built means changing validation in Domains 3, 4, 5 and 6 and re-testing their slices. The boundary questions (boards versus dashboards, scheduling splits, reminders, emergency workflow ownership) are cheap to change.',
         ids='ADM-004, ADM-008, ADM-009, ADM-007, ADM-005, ADM-012, ADM-010, ADM-011, ANL-011, ANC-004, PEX-005'),
    dict(id='T09', title='Clinical record model, signature and the legal health record',
         lead='Chief architect and CMIO with HIM leadership and legal', proceed='Partly', cost='High',
         position='The clinical persistence model is left open between the candidates the PRS names. Signed content is immutable and amended with provenance. Domain 10 provides the document service; Domain 6 owns the legal record, its lifecycle, retention, legal hold and disclosure, including primary ownership of clinical document attachments. What the legal record comprises per encounter type, the signature assurance level, and whether structured data is archived are not defined.',
         cost_text='The persistence model is the most expensive decision in the clinical domain to reverse: it shapes storage, templates, queries, migration and the analytical feeds, and changing it after stage 3 is a re-platforming of the clinical record. Signature assurance set too low may make signed records legally insufficient, which cannot be fixed retrospectively for records already signed. The definition of the legal record drives completeness rules, retention and disclosure; it can follow slightly later but is needed before record completion is released in stage 3.',
         ids='CLI-003, CLI-009, HIM-002, HIM-001, ESS-003, CLI-014, EBP-013, HIM-007, HIM-008, HIM-009, HIM-012, HIM-013'),
    dict(id='T10', title='Order-result contract and diagnostic system sourcing',
         lead='Enterprise Architecture Board with the Domain 3 and Domain 4 owners', proceed='Partly', cost='High',
         position='Domain 3 owns the order and its lifecycle, result presentation, review and release; Domain 4 owns fulfilment, result validation, versioning and critical-result communication. Nursing observations are in Domain 3; ICU and device observations in Domain 4. Human milk management sits with the blood bank module. Whether each of laboratory, radiology, imaging archive, pathology and blood bank is built or integrated is not decided.',
         cost_text='The contract can be built first against a simulator (slice OR-1), which is how the plan contains this risk. Build-or-integrate cannot be deferred past the start of stage 4: it decides whether Domain 4 delivers full workflows or adapters to external systems, which changes the size and nature of slices OR-2, OR-4 and OR-5 and the interfaces ACC-005 must prove. Integrating a product also has to pass the PRS dependency policy. Moving the result-validation or observation boundary after both sides are built means reworking the contract and its consumers in Domains 6, 7, 8 and 9.',
         ids='ANC-001, CLI-010, ANC-007, PEX-003, EBP-010, ANC-009, CLI-002, ANC-003'),
    dict(id='T11', title='Decision-support runtime and clinical safety governance',
         lead='Clinical informatics with clinical governance', proceed='Partly', cost='Medium',
         position='A decision-support service evaluates versioned rules at workflow hooks, with the rule representation left open. The override review threshold defaults to the PRS value of 70% (the Architecture says 90% for interruptive alerts). Domain 3 holds the clinical hazard log and usability evidence for the product.',
         cost_text='Rules, order-set logic and pathway criteria are all written in whatever representation is chosen. Changing it after content exists means rewriting and re-validating every rule and pathway, with clinical re-approval (ACC-010). The cost is contained while content is small, so it is cheapest to decide before stage 3 content authoring begins. The review threshold is a configuration value and cheap to change. The hazard log must have an owner and tool before the first Tier 1 gate.',
         ids='CLI-005, EBP-009, CLI-011, CLI-013'),
    dict(id='T12', title='Medication, pharmacy and stock ownership',
         lead='Enterprise Architecture Board with pharmacy leadership', proceed='Yes', cost='Medium',
         position='Domain 3 owns prescribing, pharmacy verification, dispensing workflow, formulary use and the administration record; Domain 4 coordinates administration in theatre and ICU through the Domain 3 service; Domain 5 owns the single stock ledger, including pharmacy and cabinet stock, and pharmacy billing. Blood units and implants are held clinically in Domain 4 and by quantity in the ledger. A ledger outage does not block dispensing.',
         cost_text='A different ownership moves requirements between slices OR-6 and BC-6 and between teams, but both slices are needed in the same stage either way, so the sequence holds. The real exposure is a second stock ledger appearing if pharmacy stock is moved without the single-ledger rule, and the behaviour of dispensing when stock data is missing or a lot is flagged: that is a patient-safety rule that pharmacy and clinical governance must approve before the medication gate, and the working position is only a proposal.',
         ids='CLI-001, ANC-002, FIN-001, EBP-018, FIN-010, ANC-005, FIN-004, FIN-005, FIN-002'),
    dict(id='T13', title='Offline bedside scope',
         lead='Clinical governance committee', proceed='Yes', cost='Medium',
         position='No bedside safety check (medication, specimen, transfusion, milk) runs offline by default. The offline edge caches and synchronizes, and which actions may complete offline is a governed configuration.',
         cost_text='The default is the safe one, so proceeding carries no safety cost. The cost is functional: if governance later requires bedside verification to continue through a network loss, the edge needs local verification data, conflict rules and reconciliation that were not built, and the downtime procedures rehearsed for ACC-007 change. Deciding before stage 4 avoids building the edge twice.',
         ids='ISE-006, CLI-006, ANC-006'),
    dict(id='T14', title='Pathway governance and behaviour',
         lead='Clinical governance committee', proceed='Yes', cost='Medium',
         position='A named clinical owner and governance body approve each pathway version; published versions are immutable. Instances stay on their version and are flagged for review when content is suspended; an overdue review does not suspend content automatically. One instance per pathway per encounter. A clinician may confirm against a non-eligible result with a reason. Evaluated input values are kept as a non-authoritative snapshot. Domain 9 defines measures and Domain 8 computes them.',
         cost_text='Most of these are behaviours behind configuration or contained in Domain 9, and changing them is rework within one domain. Two are not: whether pathway decision logic falls under medical-device or clinical-software regulation, which could add a conformity process to every pathway release, and who the content owners and approvers are, without which no pathway can pass ACC-010. Both are needed before the first pathway is published in stage 3.',
         ids='EBP-001, EBP-020, EBP-002, EBP-003, EBP-005, EBP-006, EBP-007, EBP-011, EBP-012, EBP-014, EBP-015, EBP-004, EBP-022'),
    dict(id='T15', title='Revenue-cycle jurisdiction profile and finance policy',
         lead='CFO with revenue cycle and HIM', proceed='Partly', cost='High',
         position='Charge capture, pricing, billing and claims are built as configurable engines with jurisdiction and payer specifics in adapters. Tariffs, payer integrations, claim formats, coding systems and reference-date rules, tax and accounting requirements, payment channels, account granularity and the point at which medication is charged are not defined.',
         cost_text='The engines can be built on the working position. The jurisdiction profile cannot be guessed: claim formats, coding systems and tax rules determine what charge capture and coding must record, and a gap found late reaches back into charge items and coded encounters already produced. Claims cannot be tested, and so the stage 5 gate cannot pass, without the real payer formats. Payer onboarding and certification lead time is outside the project\'s control, so this theme should start well before stage 5.',
         ids='FIN-003, HIM-005, FIN-007, FIN-006, FIN-008, FIN-012'),
    dict(id='T16', title='Patient portal scope',
         lead='Patient Experience Office with the product owner', proceed='Yes', cost='Low',
         position='Patients request appointments and staff confirm them; no direct self-booking. The mobile form, the communication channels, reminders for patients without an account, and where staff-facing engagement functions live are open. Third-party application access is a Must requirement whose timing within the portal release is open (covered under interoperability).',
         cost_text='These are product-scope choices inside one domain with mostly Should-priority requirements. Deciding differently adds or removes features in slice RC-6 without disturbing other slices. The one item with wider reach is direct self-booking, which would need Domain 1 scheduling rules exposed to patients.',
         ids='PEX-006, PEX-008, PEX-010, PEX-004'),
    dict(id='T17', title='Analytics, AI and maturity targets',
         lead='Data Governance Council with clinical governance', proceed='Yes', cost='Low',
         position='Analytics runs isolated from clinical transactions (see technology for physical or logical isolation) and never writes back. AI is optional, advisory and human-supervised, starting with non-clinical use cases. Domain 8 delivers other domains\' reports from governed feeds; Domains 2 and 10 own live operational telemetry. Maturity targets, the research data model and metric approval routing are open.',
         cost_text='The data platform and dashboards are built the same way whichever way these go. AI is optional and gated by its own use-case approval, so nothing depends on it. The research model is an additional projection of curated data. The only item that can hold a gate is metric ownership and approval routing: a dashboard cannot be published as governed without an approved definition and owner.',
         ids='ANL-001, ANL-008, ANL-002, ANL-013, ANL-006, ANL-005, ANL-009, ANC-010, HIM-006, HIM-017'),
]

# Decisions that carry most of their theme's cost. Listed first in the plan as the ones to settle before anything else in the theme.
ANCHORS = {
    'DEC-ISE-003': 'Without it no service can be built.',
    'DEC-ISE-002': 'Fixes where the system runs and what recovery can be demonstrated.',
    'DEC-ESS-005': 'Every user and service authenticates through it from the first slice.',
    'DEC-ADM-002': 'Identifier formats and matching thresholds are written into every record; needed for ACC-004.',
    'DEC-ESS-012': 'Which code systems are licensed and used binds all coded clinical data.',
    'DEC-ISE-005': 'The tier scheme and its numeric targets are needed before any recovery or downtime gate.',
    'DEC-ESS-009': 'Sensitive categories, labels and legal basis determine every access decision on clinical data.',
    'DEC-ISE-010': 'National requirements may add data elements to registration and the clinical record.',
    'DEC-ADM-004': 'The encounter state model is referenced by every downstream domain.',
    'DEC-CLI-003': 'The clinical persistence model; the costliest clinical decision to reverse.',
    'DEC-CLI-009': 'Signature assurance cannot be raised retrospectively for records already signed.',
    'DEC-HIM-002': 'Defines what the legal record contains, which drives completeness, retention and disclosure.',
    'DEC-ANC-001': 'Build or integrate for each diagnostic system sets the scope of the stage 4 slices.',
    'DEC-CLI-010': 'The order-result contract that slice OR-1 proves against a simulator.',
    'DEC-CLI-005': 'The rule representation in which all decision-support and pathway logic is written.',
    'DEC-CLI-001': 'The medication ownership position that Domains 3, 4, 5 and 9 all depend on.',
    'DEC-FIN-004': 'Dispensing behaviour when stock data is missing is a patient-safety rule.',
    'DEC-ISE-006': 'Which bedside safety checks may run offline.',
    'DEC-EBP-001': 'No pathway can be approved without named content owners and an approval route.',
    'DEC-EBP-020': 'A regulatory classification could add a conformity process to every pathway release.',
    'DEC-FIN-003': 'Real payer, claim, coding and tax requirements; claims cannot be tested without them.',
}
