PHP code example of clinically / laravel-halaxy

1. Go to this page and download the library: Download clinically/laravel-halaxy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clinically / laravel-halaxy example snippets


use Clinically\Halaxy\DTOs\ContactPoint;
use Clinically\Halaxy\DTOs\PatientPayload;
use Clinically\Halaxy\Facades\Halaxy;

// Find, list, create
$patient = Halaxy::patients()->find('123456')->json();
$bundle = Halaxy::patients()->list(['_count' => 30]);

$payload = new PatientPayload(
    name: [['use' => 'official', 'given' => ['John'], 'family' => 'Doe']],
    telecom: [
        ContactPoint::mobile('+61400000000'),
        ContactPoint::email('[email protected]'),
    ],
    birthDate: '1990-01-15',
);

$created = Halaxy::patients()->create($payload);

// Partial update (JSON merge-patch)
Halaxy::patients()->update('123456', $payload);

// Full replace (PUT) — destructive: writable properties omitted from the
// payload are REMOVED from the profile (only file attachments survive).
// Always send the complete desired state.
Halaxy::patients()->replace('123456', $payload);

// Raw arrays remain supported for backwards compatibility, but typed contact
// points enforce Halaxy's 

$paginator = Halaxy::patients()
    ->query()
    ->where('family', 'Doe')
    ->where('_lastUpdated', 'gt', '2024-01-01')
    ->orderBy('family')
    ->paginate(50);

foreach ($paginator->items() as $patient) {
    // current page
}

foreach ($paginator->all() as $patient) {
    // lazily fetches every page
}

// Find available times (start, end, and duration are     'start' => '2026-02-15T09:00:00+11:00',
    'end' => '2026-02-22T17:00:00+11:00',
    'duration' => '30',
    'show' => 'first-available',
]);

// Book
$booked = Halaxy::appointments()->book([
    'parameter' => [
        [
            'name' => 'appt-resource',
            'resource' => [
                'resourceType' => 'Appointment',
                'start' => '2026-02-15T09:00:00+11:00',
                'end' => '2026-02-15T09:30:00+11:00',
                'minutesDuration' => 30,
                'participant' => [
                    ['actor' => ['type' => 'PractitionerRole', 'reference' => 'https://au-api.halaxy.com/main/PractitionerRole/PR-123']],
                ],
            ],
        ],
        ['name' => 'patient-id', 'valueReference' => ['type' => 'Patient', 'reference' => 'https://au-api.halaxy.com/main/Patient/123456']],
        ['name' => 'healthcare-service-id', 'valueReference' => ['type' => 'HealthcareService', 'reference' => 'https://au-api.halaxy.com/main/HealthcareService/789']],
        ['name' => 'location-type', 'valueCode' => 'clinic'],
        ['name' => 'status', 'valueCode' => 'booked'],
    ],
]);

// Update (merge-patch): description, start/end, comment, participant, ...
Halaxy::appointments()->update($appointmentId, ['comment' => 'Running late']);

Halaxy::appointments()->update($appointmentId, [
    'participant' => [[
        'actor' => ['type' => 'Patient', 'reference' => "https://au-api.halaxy.com/main/Patient/{$patientId}"],
        'modifierExtension' => [[
            'url' => 'https://terminology.halaxy.com/StructureDefinition/appointment-participant-status',
            'valueCoding' => [
                'system' => 'https://au-api.halaxy.com/presets/CodeSystem/appointment-participant-status',
                'code' => 'cancelled (no charge)',
                'display' => 'cancelled (no charge)',
            ],
        ]],
    ]],
]);

use Clinically\Halaxy\DTOs\ReferralAttachment;
use Clinically\Halaxy\DTOs\ReferralPayload;

$referral = Halaxy::referrals()->create(new ReferralPayload(
    coverageReference: "Coverage/{$coverageId}",
    subjectReference: "Patient/{$patientId}",
    requesterReference: "PractitionerRole/{$requesterId}",
    created: new DateTimeImmutable('now'),
    comment: 'Specialist review requested',
    attachments: [
        new ReferralAttachment('application/pdf', $base64Data, 'referral.pdf'),
    ],
));

Halaxy::referrals()->addAttachments(
    $referralId,
    new ReferralAttachment('application/pdf', $base64Data, 'additional.pdf'),
);

$schedules = Halaxy::schedules()->list();

// Generate slots for one schedule via its $generate operation
Halaxy::schedules()->generateSlots('33001', [
    'period' => [
        'start' => '2026-02-01T09:00:00+11:00',
        'end' => '2026-02-08T17:00:00+11:00', // at least 24h after start
    ],
]);

$slots = Halaxy::slots()->list(['schedule' => 'Schedule/33001']);

$response = Halaxy::region('eu')->patients()->find('789');

$halaxy = Halaxy::for(
    tenantId: $clinic->id,
    clientId: $clinic->halaxy_client_id,
    clientSecret: $clinic->halaxy_client_secret,
    region: 'au',
);

$patients = $halaxy->patients()->list();

// One-off credentials (not cached by tenant)
$halaxy = Halaxy::withCredentials(clientId: '...', clientSecret: '...', region: 'eu');

// Cache management
Halaxy::forgetTenant($clinic->id);
Halaxy::flush();

$client = Halaxy::getClient();
$response = $client->get('Patient', ['family' => 'Doe']);

  collect(Halaxy::capabilities()->get()->json()['rest'][0]['resource'])
      ->mapWithKeys(fn ($r) => [$r['type'] => collect($r['interaction'])->pluck('code')->implode(',')]);
  

->withMiddleware(function (Middleware $middleware): void {
    $middleware->validateCsrfTokens(except: ['webhooks/halaxy', 'webhooks/halaxy/*']);
})

// e.g. routes/tenant-webhooks.php, grouped under {tenant} + tenant middleware
use Clinically\Halaxy\Webhooks\HalaxyWebhookRoutes;

HalaxyWebhookRoutes::register('halaxy');

'webhooks' => [
    // ...
    'signature_validator' => App\Webhooks\TenantHalaxySignatureValidator::class,
],

use Clinically\Halaxy\Exceptions\AuthenticationException;
use Clinically\Halaxy\Exceptions\MethodNotAllowedException;
use Clinically\Halaxy\Exceptions\NotFoundException;
use Clinically\Halaxy\Exceptions\RateLimitException;
use Clinically\Halaxy\Exceptions\ServerException;
use Clinically\Halaxy\Exceptions\ValidationException;

try {
    $response = Halaxy::patients()->find('invalid-id');
} catch (NotFoundException $e) {
    // 404
} catch (MethodNotAllowedException $e) {
    // 405 — the resource does not support this interaction at all
} catch (ValidationException $e) {
    // 400/422 — $e->operationOutcome holds the FHIR OperationOutcome issues
} catch (AuthenticationException $e) {
    // 401/403 — message 

try {
    Halaxy::documentReferences()->create($payload);
} catch (HalaxyException $e) {
    report($e);

    $e->isRetryable() ? $this->release(60) : $this->fail($e);
}
bash
php artisan vendor:publish --tag="halaxy-config"
bash
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"
php artisan migrate