/** * Element Path Resolver Utility * * Provides utilities for parsing and resolving FHIR element paths. * Used to determine parent-child relationships and check element existence * for conditional cardinality validation. * * Key Responsibilities: * - Parse element paths into components * - Get parent paths from child paths * - Check if parent elements exist in resources * - Determine if paths are root-level vs nested * * Example Usage: * ```typescript * // Check if parent exists before requiring child element * const parentPath = getParentPath('Patient.communication.language'); * // Returns: 'Patient.communication' * * if (hasParentElement(resource, 'Patient.communication.language')) { * // Parent exists, child element is truly required * } * ``` */ export interface PathComponents { /** Full path (e.g., "Patient.communication.language") */ fullPath: string; /** Resource type (e.g., "Patient") */ resourceType: string; /** Path segments without resource type (e.g., ["communication", "language"]) */ segments: string[]; /** Parent path, if any (e.g., "Patient.communication") */ parentPath: string | null; /** Whether this is a root-level element (e.g., "Patient.name") */ isRootLevel: boolean; /** Depth level (0 = resourceType, 1 = root element, 2+ = nested) */ depth: number; } /** * Parse an element path into components * * @param path - Element path (e.g., "Patient.communication.language") * @param resourceType - Resource type to validate against (optional) * @returns Parsed path components * * @example * parseElementPath('Patient.communication.language', 'Patient') * // Returns: * // { * // fullPath: 'Patient.communication.language', * // resourceType: 'Patient', * // segments: ['communication', 'language'], * // parentPath: 'Patient.communication', * // isRootLevel: false, * // depth: 2 * // } */ export declare function parseElementPath(path: string, resourceType?: string): PathComponents; /** * Get parent path from a child path * * @param path - Child element path * @returns Parent path, or null if path is resource type itself * * @example * getParentPath('Patient.communication.language') // 'Patient.communication' * getParentPath('Patient.name') // 'Patient' * getParentPath('Patient') // null */ export declare function getParentPath(path: string): string | null; /** * Check if a path represents a root-level element * * @param path - Element path * @param resourceType - Resource type * @returns True if element is at root level (e.g., "Patient.name") * * @example * isRootElement('Patient.name', 'Patient') // true * isRootElement('Patient.communication.language', 'Patient') // false */ export declare function isRootElement(path: string, resourceType: string): boolean; /** * Get all ancestor paths for an element path * * @param path - Element path * @returns Array of ancestor paths, from immediate parent to root * * @example * getAncestorPaths('Patient.contact.name.given') * // Returns: ['Patient.contact.name', 'Patient.contact', 'Patient'] */ export declare function getAncestorPaths(path: string): string[]; /** * Check if parent element exists in resource * * This is the core function for conditional cardinality checking. * Returns true if: * - Element is root-level (no parent beyond resource itself) * - Parent element exists and is not null/undefined * - Parent is an array with at least one element * * @param resource - FHIR resource * @param elementPath - Path of the child element to check * @returns True if parent exists (or element is root-level), false otherwise * * @example * // Patient without communication * hasParentElement(patient, 'Patient.communication.language') // false * * // Patient with communication * hasParentElement(patientWithComm, 'Patient.communication.language') // true * * // Root element always returns true * hasParentElement(patient, 'Patient.name') // true */ export declare function hasParentElement(resource: any, elementPath: string): boolean; /** * Check if any parent in the ancestor chain is missing * * This recursively checks all ancestors to ensure the entire * path is valid before requiring a child element. * * @param resource - FHIR resource * @param elementPath - Element path to check * @returns True if all ancestors exist, false if any are missing * * @example * // Check if Patient.contact.name.given requires validation * // Checks: Patient.contact exists, Patient.contact.name exists * hasAllAncestors(patient, 'Patient.contact.name.given') */ export declare function hasAllAncestors(resource: any, elementPath: string): boolean; /** * Check if element should be validated for required cardinality * * Combines parent existence check with root-level detection to determine * if a required element validation should be enforced. * * @param resource - FHIR resource * @param elementPath - Element path * @returns True if element should be validated as required * * @example * shouldValidateRequired(patient, 'Patient.name') // true (root level) * shouldValidateRequired(patient, 'Patient.communication.language') * // true only if patient.communication exists */ export declare function shouldValidateRequired(resource: any, elementPath: string): boolean; /** * Get detailed path information for debugging * * @param resource - FHIR resource * @param elementPath - Element path * @returns Debug information about the path */ export declare function getPathDebugInfo(resource: any, elementPath: string): { path: string; components: PathComponents; valueExists: boolean; parentExists: boolean; shouldValidate: boolean; value: any; parentValue: any; }; //# sourceMappingURL=element-path-resolver.d.ts.map