fhir-resource-diff 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/fhir-version.ts","../src/core/resource-registry.ts","../src/core/parse.ts","../src/core/rules/walk.ts","../src/core/profile-registry.ts","../src/core/rules/id-format.ts","../src/core/rules/date-format.ts","../src/core/rules/reference-format.ts","../src/core/rules/data/required-field-defs.ts","../src/core/rules/required-fields.ts","../src/core/rules/data/status-value-defs.ts","../src/core/rules/status-values.ts","../src/core/rules/codeable-concept.ts","../src/core/rules/profile-aware.ts","../src/core/rules/index.ts","../src/core/validate.ts","../src/core/classify.ts","../src/core/diff.ts","../src/core/utils/path.ts","../src/core/normalize.ts","../src/core/version.ts","../src/core/summary.ts","../src/core/envelope.ts","../src/formatters/text.ts","../src/formatters/json.ts","../src/formatters/markdown.ts"],"sourcesContent":["import type { FhirResource } from \"@/core/types.js\";\n\n/** Supported FHIR release identifiers. */\nexport type FhirVersion = \"R4\" | \"R4B\" | \"R5\";\n\nexport const SUPPORTED_FHIR_VERSIONS: readonly FhirVersion[] = [\"R4\", \"R4B\", \"R5\"] as const;\n\nexport const DEFAULT_FHIR_VERSION: FhirVersion = \"R4\";\n\n/**\n * Maps concrete FHIR version strings (as found in meta.fhirVersion or CapabilityStatement)\n * to the corresponding release identifier.\n */\nexport const VERSION_STRING_MAP: ReadonlyMap<string, FhirVersion> = new Map([\n [\"4.0.0\", \"R4\"],\n [\"4.0.1\", \"R4\"],\n [\"4.3.0\", \"R4B\"],\n [\"4.3.0-snapshot1\", \"R4B\"],\n [\"5.0.0\", \"R5\"],\n [\"5.0.0-snapshot1\", \"R5\"],\n [\"5.0.0-ballot\", \"R5\"],\n]);\n\n/**\n * Detects the FHIR version from a resource's meta.fhirVersion field.\n * Returns undefined if the field is absent or the version string is unrecognized.\n */\nexport function detectFhirVersion(resource: FhirResource): FhirVersion | undefined {\n const versionStr = resource.meta?.fhirVersion;\n if (typeof versionStr !== \"string\") return undefined;\n return VERSION_STRING_MAP.get(versionStr);\n}\n\n/**\n * Resolves a FHIR version from an explicit flag, auto-detection, or the default.\n * Priority: explicit > detected > default.\n */\nexport function resolveFhirVersion(\n explicit: FhirVersion | undefined,\n resource: FhirResource,\n): FhirVersion {\n if (explicit !== undefined) return explicit;\n return detectFhirVersion(resource) ?? DEFAULT_FHIR_VERSION;\n}\n\n/**\n * Returns a human-readable label, e.g. \"FHIR R4 (v4.0.1)\".\n */\nexport function fhirVersionLabel(version: FhirVersion): string {\n const labels: Record<FhirVersion, string> = {\n R4: \"FHIR R4 (v4.0.1)\",\n R4B: \"FHIR R4B (v4.3.0)\",\n R5: \"FHIR R5 (v5.0.0)\",\n };\n return labels[version];\n}\n\n/**\n * Returns the base URL for the HL7 FHIR spec for the given version.\n * e.g. \"https://hl7.org/fhir/R4\"\n */\nexport function fhirBaseUrl(version: FhirVersion): string {\n return `https://hl7.org/fhir/${version}`;\n}\n\n/**\n * Validates that a string is a supported FhirVersion.\n * Useful for parsing CLI flags.\n */\nexport function isSupportedFhirVersion(value: string): value is FhirVersion {\n return (SUPPORTED_FHIR_VERSIONS as readonly string[]).includes(value);\n}\n","import { DEFAULT_FHIR_VERSION, fhirBaseUrl } from \"@/core/fhir-version.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\n\nexport type ResourceCategory =\n | \"foundation\"\n | \"base\"\n | \"clinical\"\n | \"financial\"\n | \"specialized\"\n | \"conformance\";\n\nexport interface ResourceKeyField {\n /** Field name. Use \"[x]\" suffix for polymorphic fields, e.g. \"value[x]\". */\n name: string;\n /** Whether this field is required (1..1 or 1..*) in the base spec. */\n required: boolean;\n /** Concise note explaining the field's purpose, type choices, or common gotchas. */\n note: string;\n}\n\nexport interface ResourceVersionNotes {\n /** What changed moving from R4 to R4B. Omit if no significant changes. */\n \"R4→R4B\"?: string;\n /** What changed moving from R4B to R5. Omit if no significant changes. */\n \"R4B→R5\"?: string;\n}\n\nexport interface ResourceTypeInfo {\n /** The exact resourceType string, e.g. \"Patient\". */\n resourceType: string;\n /** High-level category for grouping and filtering. */\n category: ResourceCategory;\n /** Which FHIR versions include this resource type. */\n versions: readonly FhirVersion[];\n /** One-line description. Not a full definition — just enough for CLI display. */\n description: string;\n\n /**\n * FHIR Maturity Model level.\n * 1–2 = draft/experimental, 3–4 = trial use, 5 = mature trial use, \"N\" = Normative.\n * Normative means backwards-compatibility is guaranteed by HL7.\n * Omitted for rarely-used resources.\n */\n maturityLevel?: number | \"N\";\n\n /**\n * 2–3 real-world use cases. Helps product owners and newcomers understand when\n * to use this resource vs alternatives.\n */\n useCases?: readonly string[];\n\n /**\n * Key fields worth knowing, with brief explanatory notes.\n * Not a full field list — just the ones that trip people up or need context.\n */\n keyFields?: readonly ResourceKeyField[];\n\n /**\n * Notable changes at each version boundary.\n * Only populated when something meaningful changed — absence means \"no significant change\".\n */\n versionNotes?: ResourceVersionNotes;\n}\n\n/**\n * Curated registry of common FHIR resource types.\n * This is intentionally incomplete — it covers the most commonly used types.\n * Full list: https://hl7.org/fhir/resourcelist.html\n */\nexport const RESOURCE_REGISTRY: readonly ResourceTypeInfo[] = [\n // foundation\n {\n resourceType: \"Bundle\",\n category: \"foundation\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Container for a collection of resources\",\n maturityLevel: \"N\",\n useCases: [\n \"Transaction: atomic write of multiple resources to a FHIR server\",\n \"Search result set: server response to a search query\",\n \"Document: a persistent clinical document (IPS, CCD)\",\n \"Message: event notification\",\n ],\n keyFields: [\n {\n name: \"type\",\n required: true,\n note: \"document|message|transaction|transaction-response|batch|batch-response|history|searchset|collection|subscription-notification\",\n },\n {\n name: \"entry[]\",\n required: false,\n note: \"the resources; shape of entry depends on Bundle.type\",\n },\n {\n name: \"entry[].resource\",\n required: false,\n note: \"the actual resource\",\n },\n {\n name: \"entry[].request\",\n required: false,\n note: \"for transaction/batch: method + url\",\n },\n {\n name: \"entry[].response\",\n required: false,\n note: \"for transaction-response/batch-response: status\",\n },\n {\n name: \"total\",\n required: false,\n note: \"only meaningful for searchset — total matching count\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"subscription-notification added as a new Bundle type; issues field added for server-reported problems with individual entries\",\n },\n },\n {\n resourceType: \"OperationOutcome\",\n category: \"foundation\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Collection of processing messages (errors, warnings, information)\",\n maturityLevel: \"N\",\n },\n {\n resourceType: \"Parameters\",\n category: \"foundation\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Operation request/response parameters\",\n maturityLevel: \"N\",\n },\n {\n resourceType: \"Binary\",\n category: \"foundation\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Raw binary content\",\n maturityLevel: 3,\n },\n // base\n {\n resourceType: \"Patient\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Demographics and administrative information about an individual\",\n maturityLevel: \"N\",\n useCases: [\n \"Demographics and identity for individuals receiving healthcare\",\n \"Linking clinical data (observations, conditions, encounters) to a person\",\n \"Cross-system patient matching and identity resolution\",\n ],\n keyFields: [\n {\n name: \"identifier\",\n required: false,\n note: \"MRN, SSN, passport — systems commonly use multiple\",\n },\n {\n name: \"name\",\n required: false,\n note: \"HumanName array; use[official] for the primary name\",\n },\n {\n name: \"birthDate\",\n required: false,\n note: \"FHIR date: YYYY, YYYY-MM, or YYYY-MM-DD\",\n },\n {\n name: \"gender\",\n required: false,\n note: \"administrative gender: male | female | other | unknown\",\n },\n {\n name: \"address\",\n required: false,\n note: \"array — patients may have multiple (home, work, old)\",\n },\n {\n name: \"telecom\",\n required: false,\n note: \"phone/email array; rank=1 is preferred contact\",\n },\n {\n name: \"deceased[x]\",\n required: false,\n note: \"boolean or dateTime — affects active status logic\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"link field added for cross-version Patient links; contact.relationship binding relaxed\",\n },\n },\n {\n resourceType: \"Practitioner\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"A person with a formal responsibility in healthcare\",\n maturityLevel: 3,\n useCases: [\n \"Identifying the author of a clinical note\",\n \"Linking prescriptions and orders to a licensed provider\",\n \"Directory listings for healthcare professionals\",\n ],\n keyFields: [\n {\n name: \"identifier\",\n required: false,\n note: \"NPI (US), provider number — systems usually require at least one\",\n },\n {\n name: \"name\",\n required: false,\n note: \"HumanName array\",\n },\n {\n name: \"qualification[]\",\n required: false,\n note: \"licenses and certifications with issuer and period\",\n },\n ],\n versionNotes: {\n \"R4B→R5\": \"communication now includes proficiency level\",\n },\n },\n {\n resourceType: \"PractitionerRole\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Roles and specialties a practitioner is authorized to perform\",\n maturityLevel: 2,\n },\n {\n resourceType: \"Organization\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"A formally recognized grouping of people or organizations\",\n maturityLevel: 3,\n },\n {\n resourceType: \"Location\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Physical place where services are provided\",\n maturityLevel: 3,\n },\n {\n resourceType: \"Endpoint\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Technical connectivity details for a system\",\n maturityLevel: 2,\n },\n {\n resourceType: \"RelatedPerson\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Person related to the patient\",\n maturityLevel: 2,\n },\n {\n resourceType: \"HealthcareService\",\n category: \"base\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Details of a healthcare service available at a location\",\n maturityLevel: 2,\n },\n // clinical\n {\n resourceType: \"Observation\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Measurements and assertions about a patient or subject\",\n maturityLevel: \"N\",\n useCases: [\n \"Lab results: glucose, HbA1c, CBC panels, lipid panels\",\n \"Vital signs: blood pressure, heart rate, BMI, oxygen saturation\",\n \"Clinical scores, assessment findings, and survey answers\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"registered|preliminary|final|amended|corrected|cancelled|entered-in-error|unknown\",\n },\n {\n name: \"code\",\n required: true,\n note: \"what was observed — LOINC (preferred), SNOMED, local codes\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"usually Patient; can be Group, Device, or Location\",\n },\n {\n name: \"effective[x]\",\n required: false,\n note: \"when the observation was made — dateTime or Period\",\n },\n {\n name: \"value[x]\",\n required: false,\n note: \"the result — Quantity, CodeableConcept, string, boolean, integer, Range, Ratio, SampledData, time, dateTime, Period\",\n },\n {\n name: \"component[]\",\n required: false,\n note: \"for panel observations; each component has its own code + value[x] (e.g. systolic + diastolic for BP)\",\n },\n {\n name: \"referenceRange\",\n required: false,\n note: \"low/high bounds for interpreting Quantity values\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"bodyStructure field added (replaces bodySite extension); subject broadens to support more reference targets; triggeredBy added for derived observations\",\n },\n },\n {\n resourceType: \"Condition\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Detailed information about a clinical condition or diagnosis\",\n maturityLevel: 3,\n useCases: [\n \"Problem list entries: active chronic conditions\",\n \"Encounter diagnoses: the reason care was provided\",\n \"Past medical history and resolved conditions\",\n ],\n keyFields: [\n {\n name: \"clinicalStatus\",\n required: false,\n note: \"CodeableConcept — active|recurrence|relapse|inactive|remission|resolved\",\n },\n {\n name: \"verificationStatus\",\n required: false,\n note: \"CodeableConcept — unconfirmed|provisional|differential|confirmed|refuted|entered-in-error\",\n },\n {\n name: \"code\",\n required: false,\n note: \"the diagnosis (SNOMED, ICD-10, local) — surprisingly not required in base spec\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"onset[x]\",\n required: false,\n note: \"when the condition started — dateTime, Age, Period, Range, string\",\n },\n {\n name: \"abatement[x]\",\n required: false,\n note: \"when it resolved — same type choices as onset[x]\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"participant added (who was involved); stage moved to backbone element; encounter reference added directly to resource\",\n },\n },\n {\n resourceType: \"Encounter\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"An interaction during which services are provided\",\n maturityLevel: 2,\n useCases: [\n \"Inpatient admission and discharge records\",\n \"Outpatient visits and office appointments\",\n \"Emergency department presentations\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"R4/R4B: planned|arrived|triaged|in-progress|onleave|finished|cancelled|... R5: planned|in-progress|on-hold|discharged|completed|cancelled|...\",\n },\n {\n name: \"class\",\n required: true,\n note: \"R4/R4B: Coding (AMB=ambulatory, IMP=inpatient, EMER=emergency) R5: renamed to class and made CodeableConcept\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"period\",\n required: false,\n note: \"start and end datetime of the encounter\",\n },\n {\n name: \"participant[]\",\n required: false,\n note: \"practitioners involved (type + individual reference)\",\n },\n {\n name: \"diagnosis[]\",\n required: false,\n note: \"conditions and procedures linked to this encounter\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"class changed from Coding to CodeableConcept (CodeableReference); status values reworked; hospitalization renamed to admission; reason now a CodeableReference instead of CodeableConcept\",\n },\n },\n {\n resourceType: \"Procedure\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"An action performed on or for a patient\",\n maturityLevel: 3,\n useCases: [\n \"Surgical procedures and interventions\",\n \"Therapeutic procedures (dialysis, chemotherapy, physical therapy)\",\n \"Diagnostic procedures (biopsy, colonoscopy)\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"preparation|in-progress|not-done|on-hold|stopped|completed|entered-in-error|unknown\",\n },\n {\n name: \"code\",\n required: false,\n note: \"what was performed (SNOMED, CPT, local)\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"performed[x]\",\n required: false,\n note: \"when — dateTime, Period, string, Age, Range\",\n },\n {\n name: \"report[]\",\n required: false,\n note: \"linked DiagnosticReport results\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"recorded field added; report made CodeableReference; performer uses new Actor type\",\n },\n },\n {\n resourceType: \"AllergyIntolerance\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Allergy or intolerance and its clinical consequences\",\n maturityLevel: 3,\n useCases: [\n \"Medication allergies for prescribing safety checks\",\n \"Food and environmental allergen records\",\n \"Adverse reaction history\",\n ],\n keyFields: [\n {\n name: \"clinicalStatus\",\n required: false,\n note: \"CodeableConcept — active|inactive|resolved\",\n },\n {\n name: \"verificationStatus\",\n required: false,\n note: \"CodeableConcept — unconfirmed|confirmed|refuted|entered-in-error\",\n },\n {\n name: \"type\",\n required: false,\n note: \"allergy | intolerance\",\n },\n {\n name: \"code\",\n required: false,\n note: \"the allergen (RxNorm for drugs, SNOMED for substances)\",\n },\n {\n name: \"patient\",\n required: true,\n note: \"required (R4/R4B) renamed to subject in R5\",\n },\n {\n name: \"reaction[]\",\n required: false,\n note: \"manifestation descriptions and severity\",\n },\n ],\n versionNotes: {\n \"R4B→R5\": \"patient renamed to subject (breaking rename); participant added\",\n },\n },\n {\n resourceType: \"MedicationRequest\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Order or request for a medication\",\n maturityLevel: 3,\n useCases: [\n \"Prescriptions from a prescriber to a pharmacy\",\n \"Medication orders within inpatient care\",\n \"Medication plans in chronic disease management\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"active|on-hold|cancelled|completed|entered-in-error|stopped|draft|unknown\",\n },\n {\n name: \"intent\",\n required: true,\n note: \"proposal|plan|order|original-order|reflex-order|filler-order|instance-order|option\",\n },\n {\n name: \"medication[x]\",\n required: true,\n note: \"reference to Medication resource or CodeableConcept — R5 uses CodeableReference\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"authoredOn\",\n required: false,\n note: \"when the prescription was written\",\n },\n {\n name: \"dosageInstruction[]\",\n required: false,\n note: \"timing, route, dose — highly structured but verbose\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"medication[x] changed to CodeableReference; statusChanged added; informationSource added; renderedDosageInstruction added (human-readable summary)\",\n },\n },\n {\n resourceType: \"MedicationStatement\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Record of medication use\",\n maturityLevel: 3,\n },\n {\n resourceType: \"DiagnosticReport\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Findings and interpretation of diagnostic investigations\",\n maturityLevel: 3,\n useCases: [\n \"Lab report: a set of Observation results with interpretation\",\n \"Radiology report: imaging study findings\",\n \"Pathology report: tissue examination results\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"registered|partial|preliminary|final|amended|corrected|appended|cancelled|entered-in-error\",\n },\n {\n name: \"code\",\n required: true,\n note: \"the type of report (LOINC panel code, local code)\",\n },\n {\n name: \"subject\",\n required: false,\n note: \"the patient (technically optional in base spec)\",\n },\n {\n name: \"result[]\",\n required: false,\n note: \"references to Observation resources in the report\",\n },\n {\n name: \"conclusion\",\n required: false,\n note: \"free-text clinical interpretation\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"study replaces imagingStudy; note added; composition added for structured reports\",\n },\n },\n {\n resourceType: \"Immunization\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Immunization event record\",\n maturityLevel: 3,\n useCases: [\n \"Vaccination records for immunization history\",\n \"Reporting immunizations to public health registries\",\n \"Immunization forecasting input\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"completed | entered-in-error | not-done\",\n },\n {\n name: \"vaccineCode\",\n required: true,\n note: \"the vaccine administered (CVX codes in US, SNOMED)\",\n },\n {\n name: \"patient\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"occurrence[x]\",\n required: true,\n note: \"when administered — dateTime or string\",\n },\n {\n name: \"lotNumber\",\n required: false,\n note: \"manufacturer lot for traceability\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"informationSource added; basedOn added for linking to immunization recommendations\",\n },\n },\n {\n resourceType: \"CarePlan\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Plan of care for a patient\",\n maturityLevel: 2,\n },\n {\n resourceType: \"CareTeam\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Participants in coordinated care for a patient\",\n maturityLevel: 2,\n },\n {\n resourceType: \"ServiceRequest\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Record of a request for a service\",\n maturityLevel: 2,\n useCases: [\n \"Referral from a GP to a specialist\",\n \"Lab test order (precedes DiagnosticReport)\",\n \"Imaging order (precedes ImagingStudy)\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"draft|active|on-hold|revoked|completed|entered-in-error|unknown\",\n },\n {\n name: \"intent\",\n required: true,\n note: \"proposal|plan|directive|order|original-order|reflex-order|filler-order|instance-order|option\",\n },\n {\n name: \"code\",\n required: false,\n note: \"what is being requested\",\n },\n {\n name: \"subject\",\n required: true,\n note: \"the patient\",\n },\n {\n name: \"requester\",\n required: false,\n note: \"who is ordering\",\n },\n {\n name: \"performer[]\",\n required: false,\n note: \"who should fulfill the request\",\n },\n ],\n versionNotes: {\n \"R4B→R5\": \"code changed to CodeableReference; bodyStructure added; focus added\",\n },\n },\n {\n resourceType: \"DocumentReference\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Reference to a document\",\n maturityLevel: 3,\n useCases: [\n \"Clinical notes (progress notes, discharge summaries, op reports)\",\n \"Scanned or external documents attached to a patient record\",\n \"CCDA and structured clinical documents\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"current | superseded | entered-in-error\",\n },\n {\n name: \"type\",\n required: false,\n note: \"document type (LOINC document codes)\",\n },\n {\n name: \"subject\",\n required: false,\n note: \"the patient\",\n },\n {\n name: \"content[]\",\n required: true,\n note: \"the document itself — attachment with URL or base64 data\",\n },\n {\n name: \"context\",\n required: false,\n note: \"encounter, period, and clinical setting\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"docStatus made more prominent; attester replaces author for formal attestation; version added; basedOn added\",\n },\n },\n {\n resourceType: \"Consent\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Record of a consent decision\",\n maturityLevel: 2,\n },\n {\n resourceType: \"Goal\",\n category: \"clinical\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Desired outcome for a patient\",\n maturityLevel: 2,\n },\n // financial\n {\n resourceType: \"Claim\",\n category: \"financial\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Request for payment for products and/or services\",\n maturityLevel: 2,\n },\n {\n resourceType: \"Coverage\",\n category: \"financial\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Insurance or medical plan details\",\n maturityLevel: 2,\n useCases: [\n \"Insurance plan and subscriber information for claims processing\",\n \"Prior authorization eligibility checks\",\n \"Patient cost-sharing determination\",\n ],\n keyFields: [\n {\n name: \"status\",\n required: true,\n note: \"active | cancelled | draft | entered-in-error\",\n },\n {\n name: \"beneficiary\",\n required: true,\n note: \"the patient covered\",\n },\n {\n name: \"payor[]\",\n required: true,\n note: \"the insurance organization(s)\",\n },\n {\n name: \"class[]\",\n required: false,\n note: \"plan, group, and subgroup identifiers\",\n },\n ],\n versionNotes: {\n \"R4B→R5\":\n \"kind field added (insurance|self-pay|other); paymentBy added for cost-sharing parties\",\n },\n },\n {\n resourceType: \"ExplanationOfBenefit\",\n category: \"financial\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Processed claim adjudication details\",\n maturityLevel: 2,\n },\n // specialized\n {\n resourceType: \"Questionnaire\",\n category: \"specialized\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Structured set of questions\",\n maturityLevel: 3,\n },\n {\n resourceType: \"QuestionnaireResponse\",\n category: \"specialized\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Responses to a questionnaire\",\n maturityLevel: 3,\n },\n {\n resourceType: \"ResearchStudy\",\n category: \"specialized\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Investigation and analysis plan\",\n maturityLevel: 1,\n },\n // conformance\n {\n resourceType: \"CapabilityStatement\",\n category: \"conformance\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Server capability description\",\n maturityLevel: \"N\",\n },\n {\n resourceType: \"StructureDefinition\",\n category: \"conformance\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Definition of a FHIR structure (resource or data type)\",\n maturityLevel: \"N\",\n },\n {\n resourceType: \"ValueSet\",\n category: \"conformance\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Set of coded values\",\n maturityLevel: \"N\",\n },\n {\n resourceType: \"CodeSystem\",\n category: \"conformance\",\n versions: [\"R4\", \"R4B\", \"R5\"],\n description: \"Definition of a code system\",\n maturityLevel: \"N\",\n },\n];\n\n/**\n * Looks up a resource type by name (case-sensitive, exact match).\n */\nexport function getResourceInfo(resourceType: string): ResourceTypeInfo | undefined {\n return RESOURCE_REGISTRY.find((r) => r.resourceType === resourceType);\n}\n\n/**\n * Builds the HL7 documentation URL for a resource type and version.\n * e.g. getResourceDocUrl(\"Patient\", \"R4\") → \"https://hl7.org/fhir/R4/patient.html\"\n * Falls back to DEFAULT_FHIR_VERSION if version is not provided.\n */\nexport function getResourceDocUrl(resourceType: string, version?: FhirVersion): string {\n return `${fhirBaseUrl(version ?? DEFAULT_FHIR_VERSION)}/${resourceType.toLowerCase()}.html`;\n}\n\n/**\n * Returns true if the resource type is in the registry, optionally filtered by version.\n */\nexport function isKnownResourceType(resourceType: string, version?: FhirVersion): boolean {\n const info = getResourceInfo(resourceType);\n if (!info) return false;\n if (version === undefined) return true;\n return (info.versions as readonly string[]).includes(version);\n}\n\n/**\n * Returns all resource types, optionally filtered by version and/or category.\n */\nexport function listResourceTypes(filters?: {\n version?: FhirVersion;\n category?: ResourceCategory;\n}): readonly ResourceTypeInfo[] {\n if (!filters) return RESOURCE_REGISTRY;\n return RESOURCE_REGISTRY.filter((r) => {\n if (filters.version !== undefined && !(r.versions as readonly string[]).includes(filters.version)) {\n return false;\n }\n if (filters.category !== undefined && r.category !== filters.category) {\n return false;\n }\n return true;\n });\n}\n","import type { FhirResource, ParseResult } from \"@/core/types.js\";\n\n/**\n * Narrows an unknown value to FhirResource if it has a string resourceType.\n * Useful for callers that already have a parsed JS object.\n */\nexport function isFhirResource(value: unknown): value is FhirResource {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"resourceType\" in value &&\n typeof (value as { resourceType: unknown }).resourceType === \"string\"\n );\n}\n\n/**\n * Parses a raw JSON string into a FhirResource.\n * Returns a discriminated union — always check `.success` before using `.resource`.\n * Does not validate FHIR shape beyond JSON well-formedness.\n */\nexport function parseJson(input: string): ParseResult {\n let parsed: unknown;\n try {\n parsed = JSON.parse(input) as unknown;\n } catch (e) {\n const message = e instanceof SyntaxError ? e.message : \"Invalid JSON\";\n return { success: false, error: message };\n }\n\n if (!isFhirResource(parsed)) {\n return { success: false, error: \"Missing or invalid resourceType\" };\n }\n\n return { success: true, resource: parsed };\n}\n","import type { FhirResource } from \"@/core/types.js\";\n\n// JSON.parse() can produce objects with these as own enumerable keys.\n// Skip them during traversal — they should never appear in real FHIR data.\nconst PROTOTYPE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nexport type FieldVisitor = (\n path: string,\n key: string,\n value: unknown,\n parent: Record<string, unknown>,\n) => void;\n\n/** Walk every key-value pair in a FHIR resource tree, depth-first. */\nexport function walkResource(resource: FhirResource, visitor: FieldVisitor): void {\n walkObject(resource as Record<string, unknown>, \"\", visitor);\n}\n\nfunction walkObject(\n obj: Record<string, unknown>,\n prefix: string,\n visitor: FieldVisitor,\n): void {\n for (const [key, value] of Object.entries(obj)) {\n if (PROTOTYPE_KEYS.has(key)) continue;\n if (value === null || value === undefined) continue;\n const path = prefix ? `${prefix}.${key}` : key;\n visitor(path, key, value, obj);\n if (Array.isArray(value)) {\n walkArray(value, path, visitor);\n } else if (typeof value === \"object\") {\n walkObject(value as Record<string, unknown>, path, visitor);\n }\n }\n}\n\nfunction walkArray(arr: unknown[], prefix: string, visitor: FieldVisitor): void {\n for (let i = 0; i < arr.length; i++) {\n const item = arr[i];\n if (item === null || item === undefined) continue;\n const path = `${prefix}[${i}]`;\n if (Array.isArray(item)) {\n walkArray(item, path, visitor);\n } else if (typeof item === \"object\") {\n walkObject(item as Record<string, unknown>, path, visitor);\n }\n }\n}\n","/**\n * A specific, named FHIR profile with a known canonical URL.\n * Used for exact-match lookups.\n */\nexport interface ProfileInfo {\n /** The exact canonical URL of this profile. */\n canonical: string;\n /** Human-readable name, e.g. \"Vital Signs Observation\". */\n name: string;\n /** Short IG identifier for display, e.g. \"FHIR Base\", \"US Core\". */\n igShort: string;\n /** Full IG name, e.g. \"US Core Implementation Guide\". */\n ig: string;\n /** Direct link to this profile's documentation page. */\n docUrl: string;\n}\n\n/**\n * A namespace entry for an Implementation Guide.\n * Used when we recognize the IG by URL prefix but don't have the exact profile.\n */\nexport interface ProfileNamespace {\n /** URL prefix that identifies this IG, e.g. \"http://hl7.org/fhir/us/core/\". */\n prefix: string;\n /** Short IG identifier for display. */\n igShort: string;\n /** Full IG name. */\n ig: string;\n /** IG home/documentation page. */\n igUrl: string;\n}\n\nexport const KNOWN_PROFILES: readonly ProfileInfo[] = [\n // FHIR base profiles (defined in the spec itself)\n {\n canonical: \"http://hl7.org/fhir/StructureDefinition/vitalsigns\",\n name: \"Vital Signs\",\n igShort: \"FHIR Base\",\n ig: \"HL7 FHIR Base Specification\",\n docUrl: \"https://hl7.org/fhir/R4/vitalsigns.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/StructureDefinition/bodyweight\",\n name: \"Body Weight\",\n igShort: \"FHIR Base\",\n ig: \"HL7 FHIR Base Specification\",\n docUrl: \"https://hl7.org/fhir/R4/bodyweight.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/StructureDefinition/heartrate\",\n name: \"Heart Rate\",\n igShort: \"FHIR Base\",\n ig: \"HL7 FHIR Base Specification\",\n docUrl: \"https://hl7.org/fhir/R4/heartrate.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/StructureDefinition/bp\",\n name: \"Blood Pressure\",\n igShort: \"FHIR Base\",\n ig: \"HL7 FHIR Base Specification\",\n docUrl: \"https://hl7.org/fhir/R4/bp.html\",\n },\n // IPS\n {\n canonical: \"http://hl7.org/fhir/uv/ips/StructureDefinition/Bundle-uv-ips\",\n name: \"IPS Bundle\",\n igShort: \"IPS\",\n ig: \"International Patient Summary\",\n docUrl: \"https://hl7.org/fhir/uv/ips/StructureDefinition-Bundle-uv-ips.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/uv/ips/StructureDefinition/Patient-uv-ips\",\n name: \"IPS Patient\",\n igShort: \"IPS\",\n ig: \"International Patient Summary\",\n docUrl: \"https://hl7.org/fhir/uv/ips/StructureDefinition-Patient-uv-ips.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/uv/ips/StructureDefinition/Composition-uv-ips\",\n name: \"IPS Composition\",\n igShort: \"IPS\",\n ig: \"International Patient Summary\",\n docUrl: \"https://hl7.org/fhir/uv/ips/StructureDefinition-Composition-uv-ips.html\",\n },\n // US Core (selected high-traffic profiles)\n {\n canonical: \"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient\",\n name: \"US Core Patient\",\n igShort: \"US Core\",\n ig: \"US Core Implementation Guide\",\n docUrl: \"https://hl7.org/fhir/us/core/StructureDefinition-us-core-patient.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab\",\n name: \"US Core Laboratory Result Observation\",\n igShort: \"US Core\",\n ig: \"US Core Implementation Guide\",\n docUrl: \"https://hl7.org/fhir/us/core/StructureDefinition-us-core-observation-lab.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition\",\n name: \"US Core Condition\",\n igShort: \"US Core\",\n ig: \"US Core Implementation Guide\",\n docUrl: \"https://hl7.org/fhir/us/core/StructureDefinition-us-core-condition.html\",\n },\n {\n canonical: \"http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest\",\n name: \"US Core MedicationRequest\",\n igShort: \"US Core\",\n ig: \"US Core Implementation Guide\",\n docUrl: \"https://hl7.org/fhir/us/core/StructureDefinition-us-core-medicationrequest.html\",\n },\n];\n\n/**\n * Namespace entries ordered from most specific to least specific.\n * First match wins during prefix lookup.\n */\nexport const PROFILE_NAMESPACES: readonly ProfileNamespace[] = [\n // IPS\n {\n prefix: \"http://hl7.org/fhir/uv/ips/\",\n igShort: \"IPS\",\n ig: \"International Patient Summary\",\n igUrl: \"https://hl7.org/fhir/uv/ips/\",\n },\n // US Core\n {\n prefix: \"http://hl7.org/fhir/us/core/\",\n igShort: \"US Core\",\n ig: \"US Core Implementation Guide\",\n igUrl: \"https://hl7.org/fhir/us/core/\",\n },\n // AU Base\n {\n prefix: \"http://hl7.org.au/fhir/StructureDefinition/\",\n igShort: \"AU Base\",\n ig: \"AU Base Implementation Guide\",\n igUrl: \"https://build.fhir.org/ig/hl7au/au-fhir-base/\",\n },\n // AU Core\n {\n prefix: \"http://hl7.org.au/fhir/core/\",\n igShort: \"AU Core\",\n ig: \"AU Core Implementation Guide\",\n igUrl: \"https://build.fhir.org/ig/hl7au/au-fhir-core/\",\n },\n // mCode\n {\n prefix: \"http://hl7.org/fhir/us/mcode/\",\n igShort: \"mCode\",\n ig: \"minimal Common Oncology Data Elements\",\n igUrl: \"https://hl7.org/fhir/us/mcode/\",\n },\n // QI Core\n {\n prefix: \"http://hl7.org/fhir/us/qicore/\",\n igShort: \"QI Core\",\n ig: \"QI Core Implementation Guide\",\n igUrl: \"https://hl7.org/fhir/us/qicore/\",\n },\n // CARIN Blue Button\n {\n prefix: \"http://hl7.org/fhir/us/carin-bb/\",\n igShort: \"CARIN BB\",\n ig: \"CARIN Blue Button Implementation Guide\",\n igUrl: \"https://hl7.org/fhir/us/carin-bb/\",\n },\n // Da Vinci\n {\n prefix: \"http://hl7.org/fhir/us/davinci-\",\n igShort: \"Da Vinci\",\n ig: \"Da Vinci Implementation Guides\",\n igUrl: \"https://confluence.hl7.org/display/DVP\",\n },\n // SMART App Launch\n {\n prefix: \"http://hl7.org/fhir/smart-app-launch/\",\n igShort: \"SMART\",\n ig: \"SMART App Launch\",\n igUrl: \"https://hl7.org/fhir/smart-app-launch/\",\n },\n // FHIR Base profiles\n {\n prefix: \"http://hl7.org/fhir/StructureDefinition/\",\n igShort: \"FHIR Base\",\n ig: \"HL7 FHIR Base Specification\",\n igUrl: \"https://hl7.org/fhir/R4/profiling.html\",\n },\n];\n\nconst CANONICAL_URL_PATTERN = /^https?:\\/\\/.+/;\nconst URN_PATTERN = /^urn:.+/;\n\n/**\n * Returns true if the given string is a valid FHIR canonical URL.\n * Accepts http(s):// URLs and urn: URIs.\n */\nexport function isValidCanonicalUrl(url: string): boolean {\n return CANONICAL_URL_PATTERN.test(url) || URN_PATTERN.test(url);\n}\n\n/**\n * Looks up an exact profile match by canonical URL.\n * Returns undefined if not found.\n */\nexport function lookupProfile(canonical: string): ProfileInfo | undefined {\n return KNOWN_PROFILES.find((p) => p.canonical === canonical);\n}\n\n/**\n * Looks up the first matching IG namespace for a canonical URL.\n * Returns undefined if no namespace prefix matches.\n */\nexport function lookupProfileNamespace(canonical: string): ProfileNamespace | undefined {\n return PROFILE_NAMESPACES.find((ns) => canonical.startsWith(ns.prefix));\n}\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { walkResource } from \"@/core/rules/walk.js\";\n\nconst FHIR_ID_PATTERN = /^[A-Za-z0-9\\-.]{1,64}$/;\n\nexport const idFormatRule: ValidationRule = {\n id: \"fhir-id-format\",\n description: \"FHIR id values must match [A-Za-z0-9\\\\-.]{1,64}\",\n\n check(resource: FhirResource, _version?: FhirVersion): ValidationError[] {\n const findings: ValidationError[] = [];\n\n walkResource(resource, (path, key, value) => {\n if (key !== \"id\") return;\n if (typeof value !== \"string\") return;\n if (!FHIR_ID_PATTERN.test(value)) {\n findings.push({\n path,\n message: `Invalid FHIR id '${value}': must match [A-Za-z0-9\\\\-.]{1,64}`,\n severity: \"warning\",\n ruleId: \"fhir-id-format\",\n });\n }\n });\n\n return findings;\n },\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { walkResource } from \"@/core/rules/walk.js\";\n\ntype DateFieldType = \"date\" | \"dateTime\" | \"instant\";\n\nconst FHIR_DATE_PATTERN = /^\\d{4}(-\\d{2}(-\\d{2})?)?$/;\nconst FHIR_DATETIME_PATTERN =\n /^\\d{4}(-\\d{2}(-\\d{2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?(Z|[+-]\\d{2}:\\d{2}))?)?)?$/;\nconst FHIR_INSTANT_PATTERN =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$/;\n\nconst INSTANT_FIELD_NAMES = new Set([\"lastUpdated\", \"issued\", \"recorded\"]);\nconst DATETIME_FIELD_NAMES = new Set([\n \"authoredOn\",\n \"occurrenceDateTime\",\n \"onsetDateTime\",\n \"abatementDateTime\",\n \"performedDateTime\",\n]);\n\nfunction classifyDateField(key: string): DateFieldType | null {\n if (INSTANT_FIELD_NAMES.has(key)) return \"instant\";\n if (DATETIME_FIELD_NAMES.has(key) || key.endsWith(\"DateTime\")) return \"dateTime\";\n if (key === \"date\" || key.endsWith(\"Date\") || key.endsWith(\"date\")) return \"date\";\n return null;\n}\n\nfunction patternFor(type: DateFieldType): RegExp {\n if (type === \"instant\") return FHIR_INSTANT_PATTERN;\n if (type === \"dateTime\") return FHIR_DATETIME_PATTERN;\n return FHIR_DATE_PATTERN;\n}\n\nfunction exampleFor(type: DateFieldType): string {\n if (type === \"instant\") return \"e.g. 2024-03-15T10:30:00Z\";\n if (type === \"dateTime\") return \"e.g. 2024-03-15T10:30:00Z or 2024-03-15\";\n return \"e.g. 2024, 2024-03, or 2024-03-15\";\n}\n\nexport const dateFormatRule: ValidationRule = {\n id: \"fhir-date-format\",\n description: \"FHIR date/dateTime/instant fields must follow the FHIR date format subset\",\n\n check(resource: FhirResource, _version?: FhirVersion): ValidationError[] {\n const findings: ValidationError[] = [];\n\n walkResource(resource, (path, key, value) => {\n const fieldType = classifyDateField(key);\n if (fieldType === null) return;\n if (typeof value !== \"string\") return;\n if (!patternFor(fieldType).test(value)) {\n findings.push({\n path,\n message: `Invalid FHIR ${fieldType} '${value}' at '${path}': ${exampleFor(fieldType)}`,\n severity: \"warning\",\n ruleId: \"fhir-date-format\",\n });\n }\n });\n\n return findings;\n },\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { walkResource } from \"@/core/rules/walk.js\";\nimport { isKnownResourceType } from \"@/core/resource-registry.js\";\n\nconst RELATIVE_REF_PATTERN = /^[A-Z][A-Za-z]+\\/[A-Za-z0-9\\-.]{1,64}$/;\nconst FRAGMENT_REF_PATTERN = /^#.+$/;\nconst ABSOLUTE_REF_PATTERN = /^https?:\\/\\/.+/;\nconst URN_REF_PATTERN = /^urn:(uuid|oid):.+$/;\n\nfunction isValidReference(ref: string): boolean {\n return (\n RELATIVE_REF_PATTERN.test(ref) ||\n FRAGMENT_REF_PATTERN.test(ref) ||\n ABSOLUTE_REF_PATTERN.test(ref) ||\n URN_REF_PATTERN.test(ref)\n );\n}\n\nexport const referenceFormatRule: ValidationRule = {\n id: \"fhir-reference-format\",\n description:\n \"FHIR reference values must be relative (ResourceType/id), absolute URL, fragment (#id), or URN\",\n\n check(resource: FhirResource, version?: FhirVersion): ValidationError[] {\n const findings: ValidationError[] = [];\n\n walkResource(resource, (path, key, value) => {\n if (key !== \"reference\") return;\n if (typeof value !== \"string\") return;\n\n if (!isValidReference(value)) {\n findings.push({\n path,\n message: `Invalid FHIR reference '${value}' at '${path}': expected ResourceType/id, absolute URL, #fragment, or urn:uuid:/urn:oid:`,\n severity: \"warning\",\n ruleId: \"fhir-reference-format\",\n });\n return;\n }\n\n // Extra check: if relative reference and version is known, validate resource type\n if (version !== undefined && RELATIVE_REF_PATTERN.test(value)) {\n const refResourceType = value.split(\"/\")[0];\n if (refResourceType && !isKnownResourceType(refResourceType, version)) {\n findings.push({\n path,\n message: `Unknown resource type '${refResourceType}' in reference '${value}' for ${version}`,\n severity: \"warning\",\n ruleId: \"fhir-reference-format\",\n });\n }\n }\n });\n\n return findings;\n },\n};\n","import type { FhirVersion } from \"@/core/fhir-version.js\";\n\nexport interface RequiredFieldDef {\n /** Dot path from resource root, e.g. \"status\", \"code\". */\n field: string;\n /** Human-readable label for error messages. */\n label: string;\n /** Which versions require this field. If omitted, all versions. */\n versions?: readonly FhirVersion[];\n}\n\n/** Keyed by resourceType. */\nexport type RequiredFieldMap = Record<string, readonly RequiredFieldDef[]>;\n\n/**\n * Curated required fields for the top ~20 FHIR resource types.\n * These are fields marked as 1..1 or 1..* in the FHIR spec.\n * Resources not in this map are not checked (no false positives for unknown types).\n */\nexport const REQUIRED_FIELDS: RequiredFieldMap = {\n Observation: [\n { field: \"status\", label: \"status\" },\n { field: \"code\", label: \"code\" },\n ],\n Condition: [\n { field: \"subject\", label: \"subject\" },\n ],\n Procedure: [\n { field: \"status\", label: \"status\" },\n { field: \"subject\", label: \"subject\" },\n ],\n MedicationRequest: [\n { field: \"status\", label: \"status\" },\n { field: \"intent\", label: \"intent\" },\n { field: \"subject\", label: \"subject\" },\n ],\n MedicationAdministration: [\n { field: \"status\", label: \"status\" },\n { field: \"subject\", label: \"subject\" },\n ],\n MedicationStatement: [\n { field: \"status\", label: \"status\" },\n { field: \"subject\", label: \"subject\" },\n ],\n DiagnosticReport: [\n { field: \"status\", label: \"status\" },\n { field: \"code\", label: \"code\" },\n ],\n Encounter: [\n { field: \"status\", label: \"status\", versions: [\"R4\", \"R4B\"] },\n { field: \"class\", label: \"class\", versions: [\"R4\", \"R4B\"] },\n ],\n AllergyIntolerance: [\n { field: \"patient\", label: \"patient\", versions: [\"R4\", \"R4B\"] },\n { field: \"subject\", label: \"subject\", versions: [\"R5\"] },\n ],\n Immunization: [\n { field: \"status\", label: \"status\" },\n { field: \"vaccineCode\", label: \"vaccineCode\" },\n { field: \"patient\", label: \"patient\" },\n ],\n CarePlan: [\n { field: \"status\", label: \"status\" },\n { field: \"intent\", label: \"intent\" },\n { field: \"subject\", label: \"subject\" },\n ],\n ServiceRequest: [\n { field: \"status\", label: \"status\" },\n { field: \"intent\", label: \"intent\" },\n { field: \"subject\", label: \"subject\" },\n ],\n Bundle: [\n { field: \"type\", label: \"type\" },\n ],\n Composition: [\n { field: \"status\", label: \"status\" },\n { field: \"type\", label: \"type\" },\n { field: \"date\", label: \"date\" },\n { field: \"author\", label: \"author\" },\n ],\n DocumentReference: [\n { field: \"status\", label: \"status\" },\n { field: \"content\", label: \"content\" },\n ],\n Claim: [\n { field: \"status\", label: \"status\" },\n { field: \"type\", label: \"type\" },\n { field: \"use\", label: \"use\" },\n { field: \"patient\", label: \"patient\" },\n { field: \"provider\", label: \"provider\" },\n ],\n ExplanationOfBenefit: [\n { field: \"status\", label: \"status\" },\n { field: \"type\", label: \"type\" },\n { field: \"use\", label: \"use\" },\n { field: \"patient\", label: \"patient\" },\n { field: \"provider\", label: \"provider\" },\n { field: \"insurer\", label: \"insurer\" },\n { field: \"outcome\", label: \"outcome\" },\n ],\n Coverage: [\n { field: \"status\", label: \"status\" },\n { field: \"beneficiary\", label: \"beneficiary\" },\n ],\n // Organization, Patient, Practitioner — nothing truly required beyond resourceType\n Organization: [],\n Patient: [],\n Practitioner: [],\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport { fhirBaseUrl } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { REQUIRED_FIELDS } from \"@/core/rules/data/required-field-defs.js\";\n\nconst RULE_ID = \"fhir-required-fields\";\n\n/**\n * Resolves a dot-path against a resource object.\n * Returns the value at the path, or undefined if any segment is missing.\n */\nfunction resolvePath(obj: Record<string, unknown>, path: string): unknown {\n const parts = path.split(\".\");\n let current: unknown = obj;\n for (const part of parts) {\n if (current === null || current === undefined || typeof current !== \"object\") {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n}\n\n/**\n * Returns true if a field value is considered \"present\":\n * - Not null or undefined\n * - If an array, has at least one element\n */\nfunction isPresent(value: unknown): boolean {\n if (value === null || value === undefined) return false;\n if (Array.isArray(value)) return value.length > 0;\n return true;\n}\n\nexport const requiredFieldsRule: ValidationRule = {\n id: RULE_ID,\n description:\n \"Required fields for common FHIR resource types must be present (curated top ~20 types)\",\n\n check(resource: FhirResource, version?: FhirVersion): ValidationError[] {\n const defs = REQUIRED_FIELDS[resource.resourceType];\n if (defs === undefined) return [];\n\n const findings: ValidationError[] = [];\n const docUrl = version\n ? `${fhirBaseUrl(version)}/${resource.resourceType.toLowerCase()}.html`\n : `https://hl7.org/fhir/${resource.resourceType.toLowerCase()}.html`;\n\n for (const def of defs) {\n // Skip if this field is only required for certain versions and version doesn't match\n if (def.versions !== undefined && version !== undefined) {\n if (!(def.versions as readonly string[]).includes(version)) continue;\n }\n // If versions are specified but we don't know the version, skip version-specific fields\n if (def.versions !== undefined && version === undefined) continue;\n\n const value = resolvePath(resource as Record<string, unknown>, def.field);\n if (!isPresent(value)) {\n findings.push({\n path: def.field,\n message: `Missing required field '${def.label}' for ${resource.resourceType}`,\n severity: \"warning\",\n ruleId: RULE_ID,\n docUrl,\n });\n }\n }\n\n return findings;\n },\n};\n","import type { FhirVersion } from \"@/core/fhir-version.js\";\n\nexport interface StatusValueDef {\n /** The field path, e.g. \"status\" or \"clinicalStatus.coding[].code\". */\n field: string;\n /** Allowed values. */\n values: readonly string[];\n /** Which versions use this value set. If omitted, all versions. */\n versions?: readonly FhirVersion[];\n}\n\nexport type StatusValueMap = Record<string, readonly StatusValueDef[]>;\n\n/**\n * Curated status value sets for the top FHIR resource types.\n * These are required bindings — the spec does not allow other values.\n * Fields absent from a resource are not checked (required-fields rule handles that).\n */\nexport const STATUS_VALUES: StatusValueMap = {\n Observation: [\n {\n field: \"status\",\n values: [\n \"registered\",\n \"preliminary\",\n \"final\",\n \"amended\",\n \"corrected\",\n \"cancelled\",\n \"entered-in-error\",\n \"unknown\",\n ],\n },\n ],\n Condition: [\n {\n field: \"clinicalStatus.coding[].code\",\n values: [\"active\", \"recurrence\", \"relapse\", \"inactive\", \"remission\", \"resolved\"],\n },\n {\n field: \"verificationStatus.coding[].code\",\n values: [\n \"unconfirmed\",\n \"provisional\",\n \"differential\",\n \"confirmed\",\n \"refuted\",\n \"entered-in-error\",\n ],\n },\n ],\n Procedure: [\n {\n field: \"status\",\n values: [\n \"preparation\",\n \"in-progress\",\n \"not-done\",\n \"on-hold\",\n \"stopped\",\n \"completed\",\n \"entered-in-error\",\n \"unknown\",\n ],\n },\n ],\n MedicationRequest: [\n {\n field: \"status\",\n values: [\n \"active\",\n \"on-hold\",\n \"ended\",\n \"cancelled\",\n \"completed\",\n \"entered-in-error\",\n \"stopped\",\n \"draft\",\n \"unknown\",\n ],\n },\n {\n field: \"intent\",\n values: [\n \"proposal\",\n \"plan\",\n \"order\",\n \"original-order\",\n \"reflex-order\",\n \"filler-order\",\n \"instance-order\",\n \"option\",\n ],\n },\n ],\n DiagnosticReport: [\n {\n field: \"status\",\n values: [\n \"registered\",\n \"partial\",\n \"preliminary\",\n \"modified\",\n \"final\",\n \"amended\",\n \"corrected\",\n \"appended\",\n \"cancelled\",\n \"entered-in-error\",\n \"unknown\",\n ],\n },\n ],\n Encounter: [\n {\n field: \"status\",\n values: [\n \"planned\",\n \"arrived\",\n \"triaged\",\n \"in-progress\",\n \"onleave\",\n \"finished\",\n \"cancelled\",\n \"entered-in-error\",\n \"unknown\",\n ],\n versions: [\"R4\", \"R4B\"],\n },\n {\n field: \"status\",\n values: [\n \"planned\",\n \"in-progress\",\n \"on-hold\",\n \"discharged\",\n \"completed\",\n \"cancelled\",\n \"discontinued\",\n \"entered-in-error\",\n \"unknown\",\n ],\n versions: [\"R5\"],\n },\n ],\n Bundle: [\n {\n field: \"type\",\n values: [\n \"document\",\n \"message\",\n \"transaction\",\n \"transaction-response\",\n \"batch\",\n \"batch-response\",\n \"history\",\n \"searchset\",\n \"collection\",\n \"subscription-notification\",\n ],\n },\n ],\n AllergyIntolerance: [\n {\n field: \"clinicalStatus.coding[].code\",\n values: [\"active\", \"inactive\", \"resolved\"],\n },\n {\n field: \"verificationStatus.coding[].code\",\n values: [\"unconfirmed\", \"confirmed\", \"refuted\", \"entered-in-error\"],\n },\n ],\n CarePlan: [\n {\n field: \"status\",\n values: [\n \"draft\",\n \"active\",\n \"on-hold\",\n \"revoked\",\n \"completed\",\n \"entered-in-error\",\n \"unknown\",\n ],\n },\n {\n field: \"intent\",\n values: [\"proposal\", \"plan\", \"order\", \"option\", \"directive\"],\n },\n ],\n ServiceRequest: [\n {\n field: \"status\",\n values: [\n \"draft\",\n \"active\",\n \"on-hold\",\n \"revoked\",\n \"completed\",\n \"entered-in-error\",\n \"unknown\",\n ],\n },\n {\n field: \"intent\",\n values: [\n \"proposal\",\n \"plan\",\n \"directive\",\n \"order\",\n \"original-order\",\n \"reflex-order\",\n \"filler-order\",\n \"instance-order\",\n \"option\",\n ],\n },\n ],\n DocumentReference: [\n {\n field: \"status\",\n values: [\"current\", \"superseded\", \"entered-in-error\"],\n },\n ],\n Immunization: [\n {\n field: \"status\",\n values: [\"completed\", \"entered-in-error\", \"not-done\"],\n },\n ],\n Coverage: [\n {\n field: \"status\",\n values: [\"active\", \"cancelled\", \"draft\", \"entered-in-error\"],\n },\n ],\n Claim: [\n {\n field: \"status\",\n values: [\"active\", \"cancelled\", \"draft\", \"entered-in-error\"],\n },\n ],\n ExplanationOfBenefit: [\n {\n field: \"status\",\n values: [\"active\", \"cancelled\", \"draft\", \"entered-in-error\"],\n },\n {\n field: \"outcome\",\n values: [\"queued\", \"complete\", \"error\", \"partial\"],\n },\n ],\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { STATUS_VALUES } from \"@/core/rules/data/status-value-defs.js\";\n\nconst RULE_ID = \"fhir-status-values\";\n\n/**\n * Reads the value(s) at a field path that may include the `[].code` suffix\n * pattern (used for CodeableConcept coding arrays).\n *\n * Supported path forms:\n * - \"status\" → resource.status\n * - \"clinicalStatus.coding[].code\" → resource.clinicalStatus.coding[*].code\n */\nfunction readFieldValues(\n resource: Record<string, unknown>,\n field: string,\n): string[] {\n const CODING_ARRAY_PATTERN = /^(.+)\\.coding\\[\\]\\.code$/;\n const match = CODING_ARRAY_PATTERN.exec(field);\n\n if (match !== null) {\n const parentPath = match[1];\n if (parentPath === undefined) return [];\n const parent = resource[parentPath];\n if (parent === null || parent === undefined || typeof parent !== \"object\") {\n return [];\n }\n const codingArray = (parent as Record<string, unknown>)[\"coding\"];\n if (!Array.isArray(codingArray)) return [];\n const codes: string[] = [];\n for (const entry of codingArray) {\n if (entry !== null && typeof entry === \"object\") {\n const code = (entry as Record<string, unknown>)[\"code\"];\n if (typeof code === \"string\") codes.push(code);\n }\n }\n return codes;\n }\n\n // Simple field path (no dots for now — all our status fields are top-level)\n const value = resource[field];\n if (typeof value === \"string\") return [value];\n return [];\n}\n\nexport const statusValuesRule: ValidationRule = {\n id: RULE_ID,\n description:\n \"Status field values must match the FHIR-required value set for each resource type\",\n\n check(resource: FhirResource, version?: FhirVersion): ValidationError[] {\n const defs = STATUS_VALUES[resource.resourceType];\n if (defs === undefined) return [];\n\n const findings: ValidationError[] = [];\n\n for (const def of defs) {\n // Select the applicable def for this version\n if (def.versions !== undefined && version !== undefined) {\n if (!(def.versions as readonly string[]).includes(version)) continue;\n }\n\n const values = readFieldValues(resource as Record<string, unknown>, def.field);\n\n // If field is absent, skip — required-fields rule handles that\n if (values.length === 0) continue;\n\n for (const actual of values) {\n if (!def.values.includes(actual)) {\n findings.push({\n path: def.field.replace(\".coding[].code\", \"\"),\n message: `Invalid value '${actual}' for ${resource.resourceType}.${def.field}. Expected one of: ${def.values.join(\", \")}`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n }\n }\n }\n\n return findings;\n },\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport { walkResource } from \"@/core/rules/walk.js\";\n\nconst RULE_ID = \"fhir-codeable-concept\";\n\nconst URI_PREFIXES = [\"http://\", \"https://\", \"urn:\"] as const;\n\n/** Resource fields that should be CodeableConcepts (not plain strings). */\nconst KNOWN_CODEABLE_CONCEPT_FIELDS: Record<string, readonly string[]> = {\n Observation: [\"code\", \"valueCodeableConcept\", \"category\"],\n Condition: [\"code\", \"clinicalStatus\", \"verificationStatus\", \"category\", \"severity\"],\n Procedure: [\"code\", \"category\"],\n MedicationRequest: [\"medicationCodeableConcept\"],\n DiagnosticReport: [\"code\", \"category\"],\n AllergyIntolerance: [\"code\", \"clinicalStatus\", \"verificationStatus\", \"type\", \"category\"],\n Immunization: [\"vaccineCode\"],\n ServiceRequest: [\"code\", \"category\"],\n};\n\nfunction isValidUri(value: string): boolean {\n return URI_PREFIXES.some((prefix) => value.startsWith(prefix));\n}\n\nfunction checkCodingEntry(\n coding: Record<string, unknown>,\n path: string,\n findings: ValidationError[],\n): void {\n const hasSystem = \"system\" in coding;\n const hasCode = \"code\" in coding;\n\n if (hasSystem && !hasCode) {\n findings.push({\n path,\n message: `Coding at '${path}' has 'system' but is missing 'code'`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n return;\n }\n\n if (hasCode && !hasSystem) {\n findings.push({\n path,\n message: `Coding at '${path}' has 'code' but is missing 'system'`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n return;\n }\n\n if (!hasSystem && !hasCode) return;\n\n // Both present — validate URI format and non-empty code\n const systemVal = coding[\"system\"];\n const codeVal = coding[\"code\"];\n\n if (typeof systemVal === \"string\" && !isValidUri(systemVal)) {\n findings.push({\n path: `${path}.system`,\n message: `Coding 'system' should be a URI starting with http://, https://, or urn: — got '${systemVal}'`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n }\n\n if (typeof codeVal === \"string\" && codeVal.trim() === \"\") {\n findings.push({\n path: `${path}.code`,\n message: `Coding 'code' must be a non-empty string`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n }\n}\n\nexport const codeableConceptRule: ValidationRule = {\n id: RULE_ID,\n description:\n \"Coding and CodeableConcept objects must have correct shape; known CodeableConcept fields must not be plain strings\",\n\n check(resource: FhirResource, _version?: FhirVersion): ValidationError[] {\n const findings: ValidationError[] = [];\n\n // Check 1: Top-level known CodeableConcept fields must not be plain strings\n const knownFields = KNOWN_CODEABLE_CONCEPT_FIELDS[resource.resourceType];\n if (knownFields !== undefined) {\n for (const field of knownFields) {\n const value = (resource as Record<string, unknown>)[field];\n if (typeof value === \"string\") {\n findings.push({\n path: field,\n message: `'${field}' should be a CodeableConcept object, not a plain string`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n }\n }\n }\n\n // Check 2 & 3: Walk the resource tree looking for \"coding\" array keys.\n // When found, inspect the parent (CodeableConcept) and each Coding element.\n walkResource(resource, (path, key, value, parent) => {\n if (key !== \"coding\") return;\n\n // The parent is the CodeableConcept object — path is the CC path\n // `path` here is the path to the \"coding\" field itself, e.g. \"code.coding\"\n const ccPath = path.endsWith(\".coding\")\n ? path.slice(0, -\".coding\".length)\n : path;\n\n if (!Array.isArray(value)) {\n findings.push({\n path,\n message: `'coding' must be an array`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n return;\n }\n\n // Empty coding array with no text on parent\n if (value.length === 0 && typeof parent[\"text\"] !== \"string\") {\n findings.push({\n path: ccPath,\n message: `CodeableConcept has empty 'coding' array and no 'text' — it carries no meaning`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n return;\n }\n\n // Check each Coding entry\n for (let i = 0; i < value.length; i++) {\n const entry: unknown = value[i];\n if (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) continue;\n checkCodingEntry(\n entry as Record<string, unknown>,\n `${path}[${i}]`,\n findings,\n );\n }\n });\n\n return findings;\n },\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport type { ValidationRule } from \"@/core/rules/index.js\";\nimport {\n isValidCanonicalUrl,\n lookupProfile,\n lookupProfileNamespace,\n} from \"@/core/profile-registry.js\";\n\nconst HL7_VALIDATOR_URL = \"https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator\";\nconst RULE_ID = \"fhir-profile-aware\";\n\nexport const profileAwareRule: ValidationRule = {\n id: RULE_ID,\n description: \"Validates meta.profile entries and identifies known IGs and profiles\",\n\n check(resource: FhirResource, _version?: FhirVersion): ValidationError[] {\n const findings: ValidationError[] = [];\n\n const metaRaw = resource.meta as Record<string, unknown> | undefined;\n if (!metaRaw) return findings;\n\n const profileField: unknown = metaRaw[\"profile\"];\n if (!Array.isArray(profileField) || profileField.length === 0) return findings;\n\n const profileArray = profileField as unknown[];\n for (let i = 0; i < profileArray.length; i++) {\n const entry: unknown = profileArray[i];\n const path = `meta.profile[${i}]`;\n\n if (typeof entry !== \"string\") {\n findings.push({\n path,\n message: \"meta.profile entries must be strings\",\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n continue;\n }\n\n if (!isValidCanonicalUrl(entry)) {\n findings.push({\n path,\n message: `Profile URL \"${entry}\" is not a valid canonical URL (must be an absolute URI)`,\n severity: \"warning\",\n ruleId: RULE_ID,\n });\n continue;\n }\n\n const exactMatch = lookupProfile(entry);\n if (exactMatch !== undefined) {\n findings.push({\n path,\n message: `Declares ${exactMatch.igShort} profile \"${exactMatch.name}\" → ${exactMatch.docUrl}`,\n severity: \"info\",\n docUrl: exactMatch.docUrl,\n ruleId: RULE_ID,\n });\n continue;\n }\n\n const namespaceMatch = lookupProfileNamespace(entry);\n if (namespaceMatch !== undefined) {\n findings.push({\n path,\n message: `Declares ${namespaceMatch.igShort} profile (${namespaceMatch.ig}) — for conformance validation load the IG in the HL7 FHIR Validator → ${namespaceMatch.igUrl}`,\n severity: \"info\",\n docUrl: namespaceMatch.igUrl,\n ruleId: RULE_ID,\n });\n continue;\n }\n\n findings.push({\n path,\n message: `Declares profile ${entry} — for conformance validation use the HL7 FHIR Validator with the relevant IG loaded → ${HL7_VALIDATOR_URL}`,\n severity: \"info\",\n docUrl: HL7_VALIDATOR_URL,\n ruleId: RULE_ID,\n });\n }\n\n return findings;\n },\n};\n","import type { FhirResource, ValidationError } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\n\n/**\n * A validation rule that inspects a parsed FHIR resource and returns\n * zero or more validation findings (warnings/info).\n */\nexport interface ValidationRule {\n /** Unique rule identifier, e.g. \"fhir-id-format\". */\n id: string;\n /** Human-readable short description. */\n description: string;\n /** Run the rule against a resource. Returns findings (empty = pass). */\n check(resource: FhirResource, version?: FhirVersion): ValidationError[];\n}\n\nexport { walkResource } from \"@/core/rules/walk.js\";\n\nimport { idFormatRule } from \"@/core/rules/id-format.js\";\nimport { dateFormatRule } from \"@/core/rules/date-format.js\";\nimport { referenceFormatRule } from \"@/core/rules/reference-format.js\";\nimport { requiredFieldsRule } from \"@/core/rules/required-fields.js\";\nimport { statusValuesRule } from \"@/core/rules/status-values.js\";\nimport { codeableConceptRule } from \"@/core/rules/codeable-concept.js\";\nimport { profileAwareRule } from \"@/core/rules/profile-aware.js\";\n\n/** Format and pattern rules — always run, no version required. */\nexport const FORMAT_RULES: readonly ValidationRule[] = [\n idFormatRule,\n dateFormatRule,\n referenceFormatRule,\n];\n\n/** Structural rules — run when version is known (version-gated). */\nexport const STRUCTURAL_RULES: readonly ValidationRule[] = [\n requiredFieldsRule,\n statusValuesRule,\n codeableConceptRule,\n];\n\n/** Profile awareness rules — always run, profile detection doesn't require version. */\nexport const PROFILE_RULES: readonly ValidationRule[] = [profileAwareRule];\n\n/** All rules combined. */\nexport const ALL_RULES: readonly ValidationRule[] = [\n ...FORMAT_RULES,\n ...STRUCTURAL_RULES,\n ...PROFILE_RULES,\n];\n\n/** Run a set of rules against a resource and collect all findings. */\nexport function runRules(\n resource: FhirResource,\n rules: readonly ValidationRule[],\n version?: FhirVersion,\n): ValidationError[] {\n const findings: ValidationError[] = [];\n for (const rule of rules) {\n findings.push(...rule.check(resource, version));\n }\n return findings;\n}\n","import { z } from \"zod\";\nimport type { FhirResource, ValidationError, ValidationHint, ValidationResult } from \"@/core/types.js\";\nimport type { FhirVersion } from \"@/core/fhir-version.js\";\nimport { VERSION_STRING_MAP } from \"@/core/fhir-version.js\";\nimport { isKnownResourceType } from \"@/core/resource-registry.js\";\nimport { FORMAT_RULES, PROFILE_RULES, STRUCTURAL_RULES, runRules } from \"@/core/rules/index.js\";\n\n// Internal schema — not exported. Export only `validate`.\nconst fhirMetaSchema = z\n .object({\n versionId: z.string().optional(),\n lastUpdated: z.string().optional(),\n })\n .passthrough();\n\nconst fhirResourceSchema = z\n .object({\n resourceType: z.string().min(1, \"resourceType must be a non-empty string\"),\n id: z.string().optional(),\n meta: fhirMetaSchema.optional(),\n })\n .passthrough();\n\n/**\n * Validates that a parsed FhirResource meets the minimum required shape.\n * Optionally runs version-aware checks when `version` is provided.\n */\nexport function validate(resource: FhirResource, version?: FhirVersion): ValidationResult {\n const result = fhirResourceSchema.safeParse(resource);\n\n const errors: ValidationError[] = [];\n\n if (!result.success) {\n for (const issue of result.error.issues) {\n errors.push({\n path: issue.path.join(\".\"),\n message: issue.message,\n severity: \"error\",\n });\n }\n }\n\n if (version !== undefined) {\n // Unknown resourceType warning\n if (!isKnownResourceType(resource.resourceType, version)) {\n errors.push({\n path: \"resourceType\",\n message: `resourceType '${resource.resourceType}' is not in the known registry for ${version}. This may be valid — check https://hl7.org/fhir/resourcelist.html`,\n severity: \"warning\",\n docUrl: \"https://hl7.org/fhir/resourcelist.html\",\n });\n }\n\n // Version mismatch warning\n const metaRaw = resource.meta as Record<string, unknown> | undefined;\n const metaFhirVersion = metaRaw?.[\"fhirVersion\"];\n if (typeof metaFhirVersion === \"string\") {\n const mappedVersion = VERSION_STRING_MAP.get(metaFhirVersion);\n if (mappedVersion !== version) {\n errors.push({\n path: \"meta.fhirVersion\",\n message: `meta.fhirVersion '${metaFhirVersion}' does not match expected version ${version}`,\n severity: \"warning\",\n });\n }\n }\n\n // R5 narrative info\n if (version === \"R5\") {\n const textRaw = resource[\"text\"] as Record<string, unknown> | undefined;\n if (textRaw !== undefined && textRaw !== null && typeof textRaw === \"object\") {\n if (\"status\" in textRaw && !(\"div\" in textRaw)) {\n errors.push({\n path: \"text\",\n message: \"R5 recommends narrative text with a div element\",\n severity: \"info\",\n });\n }\n }\n }\n\n }\n\n // Format and pattern rules — always run, version passed through for registry checks\n errors.push(...runRules(resource, FORMAT_RULES, version));\n\n // Structural rules — only run when version is known (value sets are version-specific)\n if (version !== undefined) {\n errors.push(...runRules(resource, STRUCTURAL_RULES, version));\n }\n\n // Profile awareness rules — always run, profile detection is version-independent\n errors.push(...runRules(resource, PROFILE_RULES, version));\n\n // The HL7 validator hint is a note about the tool's scope, not a finding about the\n // resource. It lives outside `errors` so it never inflates the warning count.\n const hint: ValidationHint | undefined =\n version !== undefined\n ? {\n message:\n \"For full FHIR schema validation, use the official HL7 FHIR Validator\",\n docUrl: \"https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator\",\n }\n : undefined;\n\n if (errors.length === 0) {\n return hint !== undefined ? { valid: true, hint } : { valid: true };\n }\n\n return hint !== undefined ? { valid: false, errors, hint } : { valid: false, errors };\n}\n","import type { DiffChangeKind } from \"@/core/types.js\";\n\n/**\n * Determines the kind of change between two values at a given path.\n * Pure function — does not recurse; the diff engine calls it per leaf node.\n */\nexport function classifyChange(left: unknown, right: unknown): DiffChangeKind {\n if (left === undefined) {\n return \"added\";\n }\n if (right === undefined) {\n return \"removed\";\n }\n if (typeof left !== typeof right) {\n return \"type-changed\";\n }\n return \"changed\";\n}\n","import type { FhirResource, DiffEntry, DiffResult, DiffOptions } from \"@/core/types.js\";\nimport { classifyChange } from \"@/core/classify.js\";\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction shouldIgnorePath(path: string, ignorePaths: string[]): boolean {\n for (const ignorePath of ignorePaths) {\n if (ignorePath === path) {\n return true;\n }\n if (ignorePath.endsWith(\".*\")) {\n const prefix = ignorePath.slice(0, -2);\n // Match direct children: path starts with prefix + \".\" and has no further \".\" or \"[\" after\n if (path.startsWith(prefix + \".\")) {\n const rest = path.slice(prefix.length + 1);\n if (!rest.includes(\".\") && !rest.includes(\"[\")) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\nfunction walkNodes(\n left: unknown,\n right: unknown,\n path: string,\n ignorePaths: string[],\n entries: DiffEntry[],\n): void {\n if (shouldIgnorePath(path, ignorePaths)) {\n return;\n }\n\n // Normalise: treat undefined as {} or [] when the other side is an object/array,\n // so that we recurse into the present side and emit leaf-level entries.\n const leftObj: unknown = left === undefined && isPlainObject(right) ? {} : left;\n const rightObj: unknown = right === undefined && isPlainObject(left) ? {} : right;\n const leftArr: unknown = left === undefined && Array.isArray(right) ? [] : leftObj;\n const rightArr: unknown = right === undefined && Array.isArray(left) ? [] : rightObj;\n\n if (isPlainObject(leftArr) && isPlainObject(rightArr)) {\n const allKeys = Array.from(\n new Set([...Object.keys(leftArr), ...Object.keys(rightArr)]),\n ).sort();\n\n for (const key of allKeys) {\n const childPath = path === \"\" ? key : `${path}.${key}`;\n walkNodes(leftArr[key], rightArr[key], childPath, ignorePaths, entries);\n }\n return;\n }\n\n if (Array.isArray(leftArr) && Array.isArray(rightArr)) {\n const maxLen = Math.max(leftArr.length, rightArr.length);\n for (let i = 0; i < maxLen; i++) {\n const childPath = `${path}[${i}]`;\n walkNodes(leftArr[i], rightArr[i], childPath, ignorePaths, entries);\n }\n return;\n }\n\n // At least one side is a primitive, undefined, or mismatched type\n if (left === undefined && right === undefined) {\n return;\n }\n\n if (left === right) {\n return;\n }\n\n // Types differ between object/array/primitive — emit type-changed without recursing\n const kind = classifyChange(left, right);\n const entry: DiffEntry = { kind, path };\n if (left !== undefined) {\n entry.left = left;\n }\n if (right !== undefined) {\n entry.right = right;\n }\n entries.push(entry);\n}\n\n/**\n * Compares two FHIR resources and returns a structured DiffResult.\n * Pure function — no I/O, no side effects.\n */\nexport function diff(\n left: FhirResource,\n right: FhirResource,\n options?: DiffOptions,\n): DiffResult {\n const ignorePaths = options?.ignorePaths ?? [];\n const entries: DiffEntry[] = [];\n\n const allKeys = Array.from(\n new Set([...Object.keys(left), ...Object.keys(right)]),\n ).sort();\n\n for (const key of allKeys) {\n walkNodes(\n left[key as keyof FhirResource],\n right[key as keyof FhirResource],\n key,\n ignorePaths,\n entries,\n );\n }\n\n return {\n resourceType: left.resourceType,\n identical: entries.length === 0,\n entries,\n };\n}\n","/**\n * Safe nested property access for plain objects.\n *\n * Both functions only traverse own properties — they never follow inherited\n * prototype chain entries. This means a crafted path like \"__proto__.polluted\"\n * simply returns undefined / does nothing, because the traversal stops as soon\n * as a segment is not an own property of the current object.\n *\n * This is conceptually similar to lodash _.get / _.set, but intentionally\n * minimal and scoped to the needs of this library.\n */\n\n/** JSON keys that, if written via bracket notation, modify Object.prototype. */\nconst PROTOTYPE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * Read a value at a dot-notation path from a plain object.\n * Returns `undefined` if any segment is missing or is not an own property.\n *\n * @example\n * getPath({ meta: { lastUpdated: \"2024-01-01\" } }, \"meta.lastUpdated\")\n * // → \"2024-01-01\"\n */\nexport function getPath(obj: Record<string, unknown>, path: string): unknown {\n const parts = path.split(\".\");\n let current: unknown = obj;\n\n for (const part of parts) {\n if (\n current === null ||\n typeof current !== \"object\" ||\n Array.isArray(current) ||\n !Object.prototype.hasOwnProperty.call(current, part)\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n\n return current;\n}\n\n/**\n * Write a value at a dot-notation path in a plain object.\n * Silently does nothing if any intermediate segment is missing, is not an own\n * property, or is a reserved prototype key.\n *\n * @example\n * const obj = { items: [3, 1, 2] };\n * setPath(obj, \"items\", [1, 2, 3]);\n */\nexport function setPath(\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void {\n const parts = path.split(\".\");\n let current: unknown = obj;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n if (\n part === undefined ||\n PROTOTYPE_KEYS.has(part) ||\n current === null ||\n typeof current !== \"object\" ||\n Array.isArray(current) ||\n !Object.prototype.hasOwnProperty.call(current, part)\n ) {\n return;\n }\n current = (current as Record<string, unknown>)[part];\n }\n\n const lastPart = parts[parts.length - 1];\n if (\n lastPart !== undefined &&\n !PROTOTYPE_KEYS.has(lastPart) &&\n current !== null &&\n typeof current === \"object\" &&\n !Array.isArray(current)\n ) {\n (current as Record<string, unknown>)[lastPart] = value;\n }\n}\n","import type { FhirResource, NormalizeOptions } from \"@/core/types.js\";\nimport { getPath, setPath } from \"@/core/utils/path.js\";\n\n// structuredClone is available in Node 17+ and modern browsers.\n// Declared here because the project's tsconfig lib target (ES2022) does not\n// include it — adding the declaration keeps the code browser-safe and avoids\n// modifying shared project configuration.\ndeclare function structuredClone<T>(value: T): T;\n\n/**\n * Matches ISO 8601 datetime strings that include a time component and a timezone offset.\n * Examples: \"2024-01-01T00:00:00+05:00\", \"2024-01-01T12:30:00-08:00\", \"2024-01-01T00:00:00Z\"\n * Does NOT match plain date strings like \"2024-01-01\".\n */\nconst DATETIME_WITH_TIME_PATTERN =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$/;\n\n/**\n * Keys that JSON.parse() can produce as own enumerable properties but that,\n * when written via bracket notation to a plain object, modify Object.prototype.\n * Unlike regular object traversal (where hasOwnProperty guards are sufficient),\n * deep-copy functions build new objects via `result[key] = ...` where `result`\n * is freshly created — so every key from the source must be checked.\n */\nconst PROTOTYPE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction trimStringsDeep(value: unknown): unknown {\n if (typeof value === \"string\") {\n return value.trim();\n }\n if (Array.isArray(value)) {\n return value.map(trimStringsDeep);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>)) {\n if (PROTOTYPE_KEYS.has(key)) continue;\n result[key] = trimStringsDeep(\n (value as Record<string, unknown>)[key],\n );\n }\n return result;\n }\n return value;\n}\n\nfunction normalizeDatesDeep(value: unknown): unknown {\n if (typeof value === \"string\") {\n if (DATETIME_WITH_TIME_PATTERN.test(value)) {\n return new Date(value).toISOString();\n }\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(normalizeDatesDeep);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>)) {\n if (PROTOTYPE_KEYS.has(key)) continue;\n result[key] = normalizeDatesDeep(\n (value as Record<string, unknown>)[key],\n );\n }\n return result;\n }\n return value;\n}\n\nfunction sortObjectKeysDeep(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(sortObjectKeysDeep);\n }\n if (value !== null && typeof value === \"object\") {\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n if (PROTOTYPE_KEYS.has(key)) continue;\n sorted[key] = sortObjectKeysDeep(\n (value as Record<string, unknown>)[key],\n );\n }\n return sorted;\n }\n return value;\n}\n\nfunction sortArrayAtPaths(\n obj: Record<string, unknown>,\n paths: string[],\n): void {\n for (const path of paths) {\n const arr = getPath(obj, path);\n if (Array.isArray(arr)) {\n const sorted = [...(arr as unknown[])].sort((a, b) => {\n const aStr = JSON.stringify(a);\n const bStr = JSON.stringify(b);\n if (aStr < bStr) return -1;\n if (aStr > bStr) return 1;\n return 0;\n });\n setPath(obj, path, sorted);\n }\n }\n}\n\n/**\n * Returns a normalized deep copy of the resource.\n * Does not mutate the input — always returns a new object.\n */\nexport function normalize(\n resource: FhirResource,\n options: NormalizeOptions,\n): FhirResource {\n let result: unknown = structuredClone(resource);\n\n if (options.trimStrings === true) {\n result = trimStringsDeep(result);\n }\n\n if (options.normalizeDates === true) {\n result = normalizeDatesDeep(result);\n }\n\n if (options.sortObjectKeys === true) {\n result = sortObjectKeysDeep(result);\n }\n\n if (\n options.sortArrayPaths !== undefined &&\n options.sortArrayPaths.length > 0\n ) {\n sortArrayAtPaths(result as Record<string, unknown>, options.sortArrayPaths);\n }\n\n return result as FhirResource;\n}\n","/**\n * Tool version constant. Update this when bumping the package version.\n * Not read from package.json at runtime (would require node:fs, breaking browser safety).\n */\nexport const TOOL_VERSION = \"0.2.0\";\n","import type { DiffResult, DiffSummary } from \"@/core/types.js\";\n\n/**\n * Computes summary counts from a DiffResult.\n * Pure function — no I/O, no side effects.\n */\nexport function summarizeDiff(result: DiffResult): DiffSummary {\n let added = 0;\n let removed = 0;\n let changed = 0;\n let typeChanged = 0;\n\n for (const entry of result.entries) {\n if (entry.kind === \"added\") added++;\n else if (entry.kind === \"removed\") removed++;\n else if (entry.kind === \"changed\") changed++;\n else if (entry.kind === \"type-changed\") typeChanged++;\n }\n\n return {\n added,\n removed,\n changed,\n typeChanged,\n total: added + removed + changed + typeChanged,\n };\n}\n","import type { OutputEnvelope } from \"@/core/types.js\";\nimport { TOOL_VERSION } from \"@/core/version.js\";\n\n/**\n * Wraps a result payload in the standard output envelope.\n * Browser-safe — reads version from a constant, not from filesystem.\n */\nexport function buildEnvelope<T>(\n command: string,\n fhirVersion: string,\n result: T,\n): OutputEnvelope<T> {\n return {\n tool: \"fhir-resource-diff\",\n version: TOOL_VERSION,\n command,\n fhirVersion,\n timestamp: new Date().toISOString(),\n result,\n };\n}\n","import type { DiffResult, ValidationResult } from \"@/core/types.js\";\n\nfunction formatValue(value: unknown): string {\n if (typeof value === \"string\") {\n return `\"${value}\"`;\n }\n return JSON.stringify(value);\n}\n\nexport function formatText(result: DiffResult): string {\n const lines: string[] = [];\n\n lines.push(`ResourceType: ${result.resourceType}`);\n\n if (result.identical) {\n lines.push(\"Status: identical\");\n return lines.join(\"\\n\");\n }\n\n const count = result.entries.length;\n lines.push(`Status: ${count} difference(s) found`);\n\n const changed = result.entries.filter((e) => e.kind === \"changed\");\n const added = result.entries.filter((e) => e.kind === \"added\");\n const removed = result.entries.filter((e) => e.kind === \"removed\");\n const typeChanged = result.entries.filter((e) => e.kind === \"type-changed\");\n\n if (changed.length > 0) {\n lines.push(\"\");\n lines.push(\"Changed:\");\n for (const entry of changed) {\n lines.push(\n ` ${entry.path}: ${formatValue(entry.left)} → ${formatValue(entry.right)}`,\n );\n }\n }\n\n if (added.length > 0) {\n lines.push(\"\");\n lines.push(\"Added:\");\n for (const entry of added) {\n lines.push(` ${entry.path}`);\n }\n }\n\n if (removed.length > 0) {\n lines.push(\"\");\n lines.push(\"Removed:\");\n for (const entry of removed) {\n lines.push(` ${entry.path}`);\n }\n }\n\n if (typeChanged.length > 0) {\n lines.push(\"\");\n lines.push(\"Type-changed:\");\n for (const entry of typeChanged) {\n lines.push(\n ` ${entry.path}: ${formatValue(entry.left)} → ${formatValue(entry.right)}`,\n );\n }\n }\n\n return lines.join(\"\\n\");\n}\n\nconst SEVERITY_ICON: Record<string, string> = {\n error: \"✗\",\n warning: \"⚠\",\n info: \"ℹ\",\n};\n\nexport function formatValidationText(result: ValidationResult): string {\n const findings = result.valid ? [] : result.errors;\n const hasErrors = findings.some((e) => e.severity === \"error\");\n const hasWarnings = findings.some((e) => e.severity === \"warning\" || e.severity === \"info\");\n\n const header = hasErrors ? \"invalid\" : hasWarnings ? \"valid (with warnings)\" : \"valid\";\n const lines: string[] = [header];\n\n for (const finding of findings) {\n const icon = SEVERITY_ICON[finding.severity] ?? \"✗\";\n const pathPrefix = finding.path !== \"\" ? `${finding.path}: ` : \"\";\n lines.push(` ${icon} ${pathPrefix}${finding.message}`);\n if (finding.docUrl !== undefined) {\n lines.push(` → ${finding.docUrl}`);\n }\n }\n\n if (result.hint !== undefined) {\n if (findings.length > 0) lines.push(\"\");\n lines.push(` ℹ ${result.hint.message}`);\n lines.push(` → ${result.hint.docUrl}`);\n }\n\n return lines.join(\"\\n\");\n}\n","import type { DiffResult, ValidationResult } from \"@/core/types.js\";\n\nexport function formatJson(result: DiffResult): string {\n return JSON.stringify(result, null, 2);\n}\n\nexport function formatValidationJson(result: ValidationResult): string {\n // Normalise to a stable shape: always include errors array, hint if present\n const output: Record<string, unknown> = { valid: result.valid };\n if (!result.valid) {\n output[\"errors\"] = result.errors;\n }\n if (result.hint !== undefined) {\n output[\"hint\"] = result.hint;\n }\n return JSON.stringify(output, null, 2);\n}\n","import type { DiffResult } from \"@/core/types.js\";\n\nfunction formatCellValue(value: unknown): string {\n if (typeof value === \"string\") {\n return `\\`\"${value}\"\\``;\n }\n return `\\`${JSON.stringify(value)}\\``;\n}\n\nexport function formatMarkdown(result: DiffResult): string {\n const lines: string[] = [];\n\n lines.push(`## Diff: ${result.resourceType}`);\n lines.push(\"\");\n\n if (result.identical) {\n lines.push(\"**Status:** identical\");\n lines.push(\"\");\n lines.push(\"| Kind | Path | Left | Right |\");\n lines.push(\"|------|------|------|-------|\");\n return lines.join(\"\\n\");\n }\n\n const count = result.entries.length;\n lines.push(`**Status:** ${count} difference(s) found`);\n lines.push(\"\");\n lines.push(\"| Kind | Path | Left | Right |\");\n lines.push(\"|------|------|------|-------|\");\n\n for (const entry of result.entries) {\n const path = `\\`${entry.path}\\``;\n let left = \"\";\n let right = \"\";\n\n if (entry.kind === \"changed\" || entry.kind === \"type-changed\") {\n left = formatCellValue(entry.left);\n right = formatCellValue(entry.right);\n }\n\n lines.push(`| ${entry.kind} | ${path} | ${left} | ${right} |`);\n }\n\n return lines.join(\"\\n\");\n}\n"],"mappings":";AAKO,IAAM,0BAAkD,CAAC,MAAM,OAAO,IAAI;AAE1E,IAAM,uBAAoC;AAM1C,IAAM,qBAAuD,oBAAI,IAAI;AAAA,EAC1E,CAAC,SAAS,IAAI;AAAA,EACd,CAAC,SAAS,IAAI;AAAA,EACd,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,mBAAmB,KAAK;AAAA,EACzB,CAAC,SAAS,IAAI;AAAA,EACd,CAAC,mBAAmB,IAAI;AAAA,EACxB,CAAC,gBAAgB,IAAI;AACvB,CAAC;AAMM,SAAS,kBAAkB,UAAiD;AACjF,QAAM,aAAa,SAAS,MAAM;AAClC,MAAI,OAAO,eAAe,SAAU,QAAO;AAC3C,SAAO,mBAAmB,IAAI,UAAU;AAC1C;AAMO,SAAS,mBACd,UACA,UACa;AACb,MAAI,aAAa,OAAW,QAAO;AACnC,SAAO,kBAAkB,QAAQ,KAAK;AACxC;AAKO,SAAS,iBAAiB,SAA8B;AAC7D,QAAM,SAAsC;AAAA,IAC1C,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,IAAI;AAAA,EACN;AACA,SAAO,OAAO,OAAO;AACvB;AAMO,SAAS,YAAY,SAA8B;AACxD,SAAO,wBAAwB,OAAO;AACxC;AAMO,SAAS,uBAAuB,OAAqC;AAC1E,SAAQ,wBAA8C,SAAS,KAAK;AACtE;;;ACFO,IAAM,oBAAiD;AAAA;AAAA,EA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