ardenexal/fhir-serialization
Composer 安装命令:
composer require ardenexal/fhir-serialization
包简介
PHP library for FHIR JSON serialization, deserialization, and validation
README 文档
README
PHP library for FHIR JSON and XML serialization and deserialization, built on top of the Symfony Serializer component.
Features
- FHIR-compliant JSON and XML serialization
- Configurable validation modes (strict/lenient/performance)
- Auto-detection of format and resource type
- Round-trip serialization testing
- Debug information support
Quick Start
use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService; // Serialize to JSON $json = $service->serializeToJson($patient); // Serialize to XML $xml = $service->serializeToXml($patient); // Deserialize from JSON $patient = $service->deserializeFromJson($json, FHIRPatient::class); // Deserialize from XML $patient = $service->deserializeFromXml($xml, FHIRPatient::class); // Auto-detect format and resource type $resource = $service->deserialize($data);
Serialization Contexts
The FHIRSerializationContextFactory provides pre-configured contexts:
use Ardenexal\FHIRTools\Component\Serialization\Context\FHIRSerializationContextFactory; $factory = new FHIRSerializationContextFactory(); // Default contexts $jsonContext = $factory->createJsonContext(); $xmlContext = $factory->createXmlContext(); // Strict validation for production $strictContext = $factory->createStrictContext('json'); // Lenient for development $lenientContext = $factory->createLenientContext('json'); // Performance-optimized (minimal validation) $perfContext = $factory->createPerformanceContext('json'); // Debug mode with detailed information $debugContext = $factory->createDebugContext('json');
Context Options
All contexts support these FHIR-specific options:
| Option | Default | Description |
|---|---|---|
fhir_strict_validation |
true |
Enable strict FHIR validation |
fhir_include_extensions |
true |
Include FHIR extensions |
fhir_include_metadata |
true |
Include metadata elements |
fhir_unknown_element_policy |
ignore |
How to handle unknown elements (ignore, error, preserve) |
fhir_validate_references |
false |
Validate FHIR references |
Pass custom overrides to any factory method:
$context = $factory->createJsonContext([ 'fhir_strict_validation' => false, 'max_depth' => 20, ]);
Round-Trip Testing
Verify serialization integrity:
// Serialize then deserialize, returns the deserialized object $roundTripped = $service->roundTripTest($patient, 'json'); $roundTripped = $service->roundTripTest($patient, 'xml');
Error Handling
use Ardenexal\FHIRTools\Component\Serialization\Exception\FHIRSerializationException; try { $patient = $service->deserializeFromJson($invalidJson, FHIRPatient::class); } catch (FHIRSerializationException $e) { echo "Serialization error: {$e->getMessage()}"; }
Symfony Integration
When used with the FHIRBundle, the service is automatically registered and available via dependency injection:
use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService; class PatientService { public function __construct( private readonly FHIRSerializationService $serializer, ) {} public function processPatientJson(string $json): object { return $this->serializer->deserializeFromJson($json, FHIRPatient::class); } }
Requirements
- PHP: 8.3 or higher
License
This component is released under the MIT License. See the LICENSE file for details.
ardenexal/fhir-serialization 适用场景与选型建议
ardenexal/fhir-serialization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.55k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ardenexal/fhir-serialization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ardenexal/fhir-serialization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 15.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-17