ardenexal / fhir-bundle
Symfony Bundle for integrating FHIR Tools components
Package info
github.com/Ardenexal/fhir-bundle
Type:symfony-bundle
pkg:composer/ardenexal/fhir-bundle
Requires
- php: >=8.3
- ardenexal/fhir-code-generation: ^0.2
- ardenexal/fhir-path: ^0.2
- ardenexal/fhir-serialization: ^0.2
- symfony/config: ^6.4|^7.4
- symfony/dependency-injection: ^6.4|^7.4
- symfony/framework-bundle: ^6.4|^7.4
- symfony/yaml: ^6.4|^7.4
Requires (Dev)
- giorgiosironi/eris: ^1.0
- phpunit/phpunit: ^12.5
- symfony/phpunit-bridge: ^6.4|^7.4
README
Symfony Bundle for integrating FHIR Tools components into Symfony applications. Provides automatic service registration, console commands, and semantic configuration.
Features
- Automatic service registration in the Symfony container
- Console commands for FHIR generation and FHIRPath evaluation
- Semantic configuration through YAML
- Symfony Flex recipe for automatic setup
Installation
This bundle is part of the PHP FHIR Tools monorepo. It is registered automatically when the project is set up.
Manual Registration
If needed, register the bundle in config/bundles.php:
return [ // ... \Ardenexal\FHIRTools\Bundle\FHIRBundle\src\FHIRBundle::class => ['all' => true], ];
Configuration
Basic Configuration
# config/packages/fhir.yaml fhir: output_directory: '%kernel.project_dir%/output' # where generated models are written cache_directory: '%kernel.cache_dir%/fhir' default_version: R4B # R4 | R4B | R5 validation: enabled: true strict_mode: false path: cache_size: 100 # max cached FHIRPath expressions serialization: metadata_cache_pool: cache.app # PSR-6 pool for property metadata; set to ~ to disable enable_cache_warmer: false # set to true to pre-populate metadata cache on cache:warmup
Metadata Caching
The bundle uses a PSR-6 cache pool to store FHIR property metadata so it doesn't need to be resolved via reflection on every request.
metadata_cache_pool— the Symfony cache pool service ID to use (default:cache.app). Set to~(null) to disable persistent caching and always resolve from attributes at runtime.enable_cache_warmer— whentrue, registers akernel.cache_warmerthat pre-populates the pool for all discovered FHIR model classes duringbin/console cache:warmup. Defaults tofalseto avoid slowing down deployments when not needed. Only takes effect whenmetadata_cache_poolis set.
# To pre-warm a dedicated pool: fhir: serialization: metadata_cache_pool: cache.fhir_metadata enable_cache_warmer: true
Registered Services
| Service ID | Class | Description |
|---|---|---|
fhir.model_generator |
FHIRModelGenerator |
Generates FHIR model classes |
fhir.valueset_generator |
FHIRValueSetGenerator |
Generates FHIR value set enums |
fhir.serialization_service |
FHIRSerializationService |
FHIR serialization and deserialization |
fhir.package_loader |
PackageLoader |
Loads FHIR packages from registries |
fhir.builder_context |
BuilderContext |
Code generation context |
fhir.path_service |
FHIRPathService |
Evaluates FHIRPath expressions |
Using Services
use Ardenexal\FHIRTools\Component\FHIRPath\Service\FHIRPathService; use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService; class FHIRController extends AbstractController { public function __construct( private readonly FHIRSerializationService $serializer, private readonly FHIRPathService $pathService, ) {} public function serializePatient(object $patient): JsonResponse { $json = $this->serializer->serializeToJson($patient); return new JsonResponse($json, json: true); } public function queryPatient(object $patient): JsonResponse { $result = $this->pathService->evaluate('name.given', $patient); return new JsonResponse($result->toArray()); } }
Console Commands
Generate FHIR Models
# Generate models from a specific FHIR package php bin/console fhir:generate --package=hl7.fhir.r4.core -vvv # Generate using only cached packages (no network) php bin/console fhir:generate --package=hl7.fhir.r4.core --offline -vvv
FHIRPath Commands
# Evaluate FHIRPath expression php bin/console fhir:path:evaluate "Patient.name.given" patient.json # Output formats php bin/console fhir:path:evaluate "name.given" patient.json --format=json --pretty php bin/console fhir:path:evaluate "name.given" patient.json --format=count # Show cache statistics php bin/console fhir:path:evaluate "name" patient.json -v # Validate FHIRPath expression syntax php bin/console fhir:path:validate "name.where(use = 'official').given.first()"
Requirements
- PHP: 8.3 or higher
- Symfony: 6.4+
License
This bundle is released under the MIT License. See the LICENSE file for details.