Skip to content

Commit c8a4e3c

Browse files
committed
refactor: reorganize FHIR bundle structure and update configuration files
1 parent 8384684 commit c8a4e3c

1,178 files changed

Lines changed: 536 additions & 55609 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 130 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,161 @@
11
# PHP FHIR Tools
22

3-
This project generates PHP model classes and enums from FHIR Structure Definitions using Symfony Console and Nette PhpGenerator. It also provides a comprehensive FHIR serialization system for converting between FHIR objects and JSON/XML formats.
3+
A PHP library monorepo for working with [FHIR](https://www.hl7.org/fhir/) (Fast Healthcare Interoperability Resources). This monorepo contains multiple standalone packages that can be used independently or together:
44

5-
## Requirements
6-
- PHP >= 8.2
7-
- Composer
5+
- **FHIR Code Generation**: Generate PHP model classes from FHIR Structure Definitions
6+
- **FHIR Serialization**: JSON/XML serialization and deserialization
7+
- **FHIRPath**: Expression evaluator for FHIRPath 2.0
8+
- **FHIR Models**: Pre-generated FHIR model classes (R4, R4B, R5)
9+
- **FHIR Bundle**: Symfony integration bundle
810

911
## Installation
10-
Clone the repository and install dependencies:
12+
13+
### As a Library (Recommended)
14+
15+
Install individual components in your project:
16+
1117
```bash
12-
composer install
18+
# For Symfony applications - includes console commands
19+
composer require ardenexal/fhir-bundle
20+
21+
# For code generation
22+
composer require ardenexal/fhir-code-generation
23+
24+
# For serialization
25+
composer require ardenexal/fhir-serialization
26+
27+
# For FHIRPath evaluation
28+
composer require ardenexal/fhir-path
29+
30+
# For pre-generated models
31+
composer require ardenexal/fhir-models
1332
```
1433

15-
## Usage
16-
Run the Symfony Console application:
34+
### For Development
35+
36+
Clone and develop on this monorepo:
37+
1738
```bash
18-
php bin/console
39+
git clone https://github.com/Ardenexal/php-fhir-tools.git
40+
cd php-fhir-tools
41+
composer install
1942
```
2043

21-
### Available Commands
44+
## Quick Start
2245

23-
#### `fhir:generate`
24-
Generates FHIR model classes from FHIR definitions.
46+
### Using FHIR Bundle in Symfony
2547

26-
**Arguments:**
27-
- `version` (required): Select FHIR version to generate model classes for.
28-
- Suggested values: `R4`, `R4B`, `R5`
48+
If you've installed `ardenexal/fhir-bundle` in your Symfony application:
2949

30-
**Example:**
3150
```bash
32-
php bin/console fhir:generate R4B
33-
```
51+
# Generate FHIR models
52+
php bin/console fhir:generate --package=hl7.fhir.r4.core -vvv
3453

35-
## FHIR Serialization
54+
# Evaluate FHIRPath expressions
55+
php bin/console fhir:path:evaluate "5 + 3"
3656

37-
This project includes a comprehensive FHIR serialization system that provides:
57+
# Against a JSON file
58+
php bin/console fhir:path:evaluate "Patient.name.given" patient.json
3859

39-
- **JSON and XML serialization** following official FHIR specifications
40-
- **Configurable validation modes** (strict/lenient)
41-
- **Flexible unknown element handling** (ignore/error/preserve)
42-
- **Performance optimization options**
43-
- **Debug information support**
44-
- **Extension handling** with proper FHIR formatting
60+
# Output as JSON
61+
php bin/console fhir:path:evaluate "name" patient.json --format=json --pretty
62+
```
4563

46-
### Quick Example
64+
### Serialize FHIR Resources
4765

4866
```php
49-
use Symfony\Component\Serializer\Serializer;
50-
use Ardenexal\FHIRTools\Serialization\FHIRResourceNormalizer;
51-
use Ardenexal\FHIRTools\Serialization\FHIRSerializationContext;
67+
use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService;
5268

53-
// Set up FHIR-aware serializer
54-
$normalizers = [new FHIRResourceNormalizer($metadataExtractor, $typeResolver)];
55-
$serializer = new Serializer($normalizers);
69+
// Serialize to JSON
70+
$json = $service->serializeToJson($patient);
5671

57-
// Configure serialization context
58-
$context = FHIRSerializationContext::forJson()
59-
->withValidationMode(FHIRSerializationContext::VALIDATION_STRICT);
72+
// Deserialize from JSON
73+
$patient = $service->deserializeFromJson($json, FHIRPatient::class);
6074

61-
// Serialize FHIR resource
62-
$json = $serializer->serialize($patient, 'json', $context->toSymfonyContext());
75+
// Auto-detect format (JSON or XML)
76+
$resource = $service->deserialize($data);
77+
```
78+
79+
## Project Structure
6380

64-
// Deserialize back to FHIR object
65-
$patient = $serializer->deserialize($json, FHIRPatient::class, 'json', $context->toSymfonyContext());
81+
```
82+
src/
83+
├── Bundle/FHIRBundle/ # Symfony Bundle integration and console commands
84+
├── Component/
85+
│ ├── CodeGeneration/src/ # FHIR model class generation from Structure Definitions
86+
│ ├── Serialization/src/ # FHIR JSON/XML serialization and deserialization
87+
│ ├── Models/src/ # Generated FHIR model classes (R4, R4B, R5)
88+
│ └── FHIRPath/src/ # FHIRPath 2.0 expression evaluator
6689
```
6790

68-
For comprehensive documentation on the serialization system, see: **[FHIR Serialization Guide](docs/FHIR-Serialization-Guide.md)**
69-
70-
## Documentation
71-
72-
- **[FHIR Serialization Guide](docs/FHIR-Serialization-Guide.md)** - Comprehensive guide for using the FHIR serialization system
73-
74-
## Composer Scripts
75-
- Run static analysis:
76-
```bash
77-
composer phpstan
78-
```
79-
- Run code style linter:
80-
```bash
81-
composer lint
82-
```
83-
- Run tests:
84-
```bash
85-
composer test
86-
```
87-
- Generate FHIR models:
88-
```bash
89-
composer run generate-models-all
90-
```
91-
92-
## GitHub Actions
93-
94-
### Regenerate FHIR Models
95-
This repository includes a GitHub Actions workflow that allows you to manually regenerate FHIR models and commit them to the main branch.
96-
97-
**To trigger the workflow:**
98-
1. Go to the "Actions" tab in the GitHub repository
99-
2. Select "Regenerate FHIR Models" from the workflows list
100-
3. Click "Run workflow"
101-
4. Optionally customize the commit message (default: "chore: regenerate FHIR models")
102-
5. Click the green "Run workflow" button
103-
104-
The workflow will:
105-
- Set up PHP 8.3 environment with required extensions
106-
- Install Composer dependencies
107-
- Run `composer run generate-models-all` to generate models for R4, R4B, and R5
108-
- Automatically commit and push changes to main if models were updated
109-
- Provide a summary of the operation
91+
Each component has its own README with detailed documentation:
11092

111-
## Project Structure
112-
- `src/` - Source code
113-
- `bin/console` - Symfony Console entry point
114-
- `resources/definitions/` - FHIR definition files
93+
- [FHIRBundle](src/Bundle/FHIRBundle/README.md) — Symfony integration and console commands
94+
- [CodeGeneration](src/Component/CodeGeneration/README.md) — Model generation from FHIR packages
95+
- [Serialization](src/Component/Serialization/README.md) — JSON/XML serialization
96+
- [FHIRPath](src/Component/FHIRPath/README.md) — FHIRPath expression evaluation
97+
- [Models](src/Component/Models/README.md) — Generated FHIR model classes
11598

116-
## License
99+
## Monorepo Structure
100+
101+
This is a library monorepo. Each component can be installed and used independently:
102+
103+
| Package | Description | Composer Install |
104+
|---------|-------------|------------------|
105+
| `ardenexal/fhir-bundle` | Symfony Bundle with console commands | `composer require ardenexal/fhir-bundle` |
106+
| `ardenexal/fhir-code-generation` | Generate PHP from FHIR definitions | `composer require ardenexal/fhir-code-generation` |
107+
| `ardenexal/fhir-serialization` | JSON/XML serialization | `composer require ardenexal/fhir-serialization` |
108+
| `ardenexal/fhir-path` | FHIRPath expression evaluator | `composer require ardenexal/fhir-path` |
109+
| `ardenexal/fhir-models` | Pre-generated FHIR models | `composer require ardenexal/fhir-models` |
117110

118-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
111+
## Development
112+
113+
### Code Quality
114+
115+
```bash
116+
# Fix code style (PSR-12 via Laravel Pint)
117+
composer lint
118+
119+
# Static analysis (PHPStan level 8)
120+
composer phpstan
121+
122+
# Run all tests
123+
composer test
124+
125+
# Run specific test suites
126+
composer test-unit
127+
composer test-integration
128+
composer test-fhir
129+
130+
# Full quality check (lint + phpstan + test)
131+
composer quality:all
132+
```
133+
134+
### Component-Specific Quality Checks
135+
136+
```bash
137+
composer quality:bundle
138+
composer quality:codegen
139+
composer quality:serialization
140+
composer quality:fhir-path
141+
```
142+
143+
## Console Commands (via FHIR Bundle)
144+
145+
When you install `ardenexal/fhir-bundle` in your Symfony application, you get these console commands:
146+
147+
| Command | Description |
148+
|---------|-------------|
149+
| `fhir:generate` | Generate PHP model classes from FHIR packages |
150+
| `fhir:path:evaluate` | Evaluate a FHIRPath expression against FHIR data |
151+
| `fhir:path:validate` | Validate FHIRPath expression syntax |
152+
153+
**Note**: These commands are only available when using the FHIR Bundle in a Symfony application. This monorepo is a library, not an application.
154+
155+
## Contributing
156+
157+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding standards, and contribution guidelines.
158+
159+
## License
119160

161+
This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.

composer.json

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ardenexal/fhir-tools",
3-
"description": "PHP CLI tool for generating FHIR types, resources, and profiles from FHIR StructureDefinitions",
4-
"type": "project",
3+
"description": "PHP monorepo library for FHIR tools - code generation, serialization, FHIRPath, and models",
4+
"type": "library",
55
"license": "MIT",
66
"minimum-stability": "stable",
77
"prefer-stable": true,
@@ -14,16 +14,12 @@
1414
"composer/semver": "^3.4.4",
1515
"nette/php-generator": "^4.2.1",
1616
"symfony/console": "^6.4|^7.4",
17-
"symfony/dotenv": "^6.4|^7.4",
1817
"symfony/filesystem": "^6.4|^7.4",
19-
"symfony/flex": "^2.10",
20-
"symfony/framework-bundle": "^6.4|^7.4",
2118
"symfony/http-client": "^6.4|^7.4",
2219
"symfony/intl": "^6.4|^7.4",
2320
"symfony/polyfill-php84": "^v1.33.0",
2421
"symfony/polyfill-php85": "^v1.33.0",
2522
"symfony/property-access": "^6.4|^7.4",
26-
"symfony/runtime": "^6.4|^7.4",
2723
"symfony/serializer": "^6.4|^7.4",
2824
"symfony/string": "^6.4|^7.4",
2925
"symfony/validator": "^6.4|^7.4",
@@ -38,14 +34,11 @@
3834
"symfony/browser-kit": "^6.4|^7.4",
3935
"symfony/css-selector": "^6.4|^7.4",
4036
"symfony/dom-crawler": "^6.4|^7.4",
41-
"symfony/maker-bundle": "^1.66.0",
4237
"symfony/phpunit-bridge": "^6.4|^7.4"
4338
},
4439
"config": {
4540
"allow-plugins": {
46-
"php-http/discovery": true,
47-
"symfony/flex": true,
48-
"symfony/runtime": true
41+
"php-http/discovery": true
4942
},
5043
"bump-after-update": true,
5144
"sort-packages": true
@@ -76,16 +69,6 @@
7669
"symfony/polyfill-php82": "*"
7770
},
7871
"scripts": {
79-
"auto-scripts": {
80-
"cache:clear": "symfony-cmd",
81-
"assets:install %PUBLIC_DIR%": "symfony-cmd"
82-
},
83-
"post-install-cmd": [
84-
"@auto-scripts"
85-
],
86-
"post-update-cmd": [
87-
"@auto-scripts"
88-
],
8972
"phpstan": "php ./vendor/bin/phpstan.phar analyse --configuration=phpstan.neon --memory-limit=-1 -v",
9073
"phpstan:bundle": "php ./vendor/bin/phpstan.phar analyse src/Bundle/ --configuration=phpstan.neon --memory-limit=-1 -v",
9174
"phpstan:codegen": "php ./vendor/bin/phpstan.phar analyse src/Component/CodeGeneration/ --configuration=phpstan.neon --memory-limit=-1 -v",
@@ -154,14 +137,5 @@
154137
"validate-recipe": "php scripts/validate-recipe.php",
155138
"test-recipe": "php ./vendor/phpunit/phpunit/phpunit tests/Integration/FlexRecipeTest.php",
156139
"test-package-installation": "php scripts/test-package-installation.php"
157-
},
158-
"conflict": {
159-
"symfony/symfony": "*"
160-
},
161-
"extra": {
162-
"symfony": {
163-
"allow-contrib": false,
164-
"require": "^6.4|^7.4"
165-
}
166140
}
167141
}

config/bundles.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/packages/cache.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

config/packages/framework.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

config/packages/property_info.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)