Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fhir Code Generation Laravel Package

ardenexal/fhir-code-generation

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require ardenexal/fhir-code-generation
    

    Ensure php-fhir-tools (parent package) is also installed if dependencies are shared.

  2. First Use Case Generate a FHIR resource class (e.g., Patient) from a FHIR profile or schema:

    use Ardenexal\FhirCodeGeneration\Generator;
    
    $generator = new Generator();
    $resourceClass = $generator->generateFromProfile('Patient', 'path/to/profile.json');
    

    Save the output to a file:

    file_put_contents('app/FHIR/Patient.php', $resourceClass);
    
  3. Key Files

    • Review src/Generator.php for core logic.
    • Check examples/ (if available) for sample profiles/schemas.

Implementation Patterns

Workflow: Profile-to-Class Generation

  1. Profile Input Use FHIR profiles (JSON/XML) to define custom resources:

    $profile = json_decode(file_get_contents('profiles/CustomObservation.json'), true);
    $generator->generateFromProfile('CustomObservation', $profile);
    
  2. Schema-Based Generation For base FHIR schemas (e.g., Patient, Encounter):

    $generator->generateFromSchema('Encounter', 'FHIR/R4');
    
  3. Integration with Laravel

    • Store generated classes in app/FHIR/ and autoload via composer.json:
      "autoload": {
        "psr-4": {
          "App\\FHIR\\": "app/FHIR/"
        }
      }
      
    • Use Laravel’s service container to bind the generator:
      $this->app->singleton(Generator::class, function ($app) {
          return new Generator(config('fhir.generator'));
      });
      
  4. Batch Processing Generate multiple resources in a loop:

    $profiles = ['Patient', 'Observation', 'Medication'];
    foreach ($profiles as $resource) {
        $generator->generateFromProfile($resource, "profiles/{$resource}.json");
    }
    

Gotchas and Tips

Pitfalls

  1. Dependency Conflicts

    • Ensure php-fhir-tools (parent package) is installed and compatible. Check for version mismatches in composer.json.
  2. Profile Validation

    • Invalid profiles may crash the generator. Validate with a FHIR validator (e.g., HAPI FHIR before generation.
  3. Namespace Collisions

    • Generated classes may conflict with existing Laravel namespaces. Prefix with FHIR\\ or use a dedicated namespace in composer.json:
      "autoload-dev": {
        "psr-4": {
          "FHIR\\": "app/FHIR/"
        }
      }
      
  4. Caching Generated Classes

    • Regenerate classes only when profiles change. Cache outputs in storage/fhir-generated/ and skip regeneration if files exist.

Debugging

  • Verbose Output: Enable debug mode in the generator (if supported) or log raw profile data:
    \Log::debug('Profile data:', ['profile' => $profile]);
    
  • Check Generated Code: Validate against FHIR specs manually or use a linter like phpstan.

Extension Points

  1. Custom Templates Override default class templates by extending the generator:

    class CustomGenerator extends Generator {
        protected function getClassTemplate(): string {
            return file_get_contents('custom/FHIRClassTemplate.twig');
        }
    }
    
  2. Post-Processing Hook into the generation pipeline to modify classes (e.g., add Laravel traits):

    $generator->setPostProcessor(function (string $classCode) {
        return str_replace('class Patient', 'class Patient extends \Illuminate\Database\Eloquent\Model', $classCode);
    });
    
  3. FHIR Version Support Explicitly specify FHIR versions (e.g., R4, STU3) to avoid ambiguity:

    $generator->generateFromSchema('Patient', 'FHIR/R4');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope