Skip to content

Commit 4a673df

Browse files
committed
feat: add FHIRPathSemanticException and FHIRTypedCollection for enhanced FHIR type handling
1 parent 4286a09 commit 4a673df

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ardenexal\FHIRTools\Component\FHIRPath\Exception;
6+
7+
/**
8+
* Exception thrown when a FHIRPath expression is semantically invalid.
9+
*
10+
* Raised during strict-mode evaluation for type errors that can only be
11+
* detected at runtime, such as accessing an undefined property on a typed
12+
* FHIR model, mismatched resource-type filters, or order-sensitive functions
13+
* applied to unordered collections.
14+
*
15+
* Extends FHIRPathException so existing catch blocks continue to work.
16+
*
17+
* @author FHIR Tools Contributors
18+
*/
19+
class FHIRPathSemanticException extends FHIRPathException
20+
{
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ardenexal\FHIRTools\Component\FHIRPath\Type;
6+
7+
/**
8+
* Wraps a raw FHIR data array with its canonical FHIR type name.
9+
*
10+
* Raw PHP arrays from FHIR resource deserialization lose their FHIR type context
11+
* when accessed via property navigation. This wrapper preserves that context so
12+
* that ofType(), is(), and type() can correctly identify complex FHIR types
13+
* (e.g. HumanName, Extension, Age) even when the underlying value is a plain array.
14+
*
15+
* FHIRPath navigation delegates through the underlying array transparently:
16+
* navigateProperty(FHIRTypedCollection, 'family') → navigateProperty($value->value, 'family')
17+
*
18+
* Consumers that need the underlying data call normalizeValue() or access
19+
* the public $value property directly.
20+
*/
21+
final class FHIRTypedCollection
22+
{
23+
/**
24+
* @param array<array-key, mixed> $value The raw FHIR data array
25+
* @param string $fhirType The canonical FHIR type name (e.g. 'HumanName', 'Extension', 'Age')
26+
*/
27+
public function __construct(
28+
public readonly array $value,
29+
public readonly string $fhirType,
30+
) {
31+
}
32+
}

0 commit comments

Comments
 (0)