PHP code example of beziworld / laravel-nfz

1. Go to this page and download the library: Download beziworld/laravel-nfz 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/ */

    

beziworld / laravel-nfz example snippets


use Beziworld\Nfz\Facades\Nfz;
use Beziworld\Nfz\Enums\ChildAgeRange;
use Beziworld\Nfz\Query\QueueSearch;

$search = QueueSearch::for('PORADNIA KARDIOLOGICZNA')   // full-text fragment, e.g. "kardiolog"
    ->in('mazowieckie')                                 // code "07", name or Province::Mazowieckie
    ->locality('WARSZAWA')
    ->urgent()                                          // stable is the default
    ->forChildren(ChildAgeRange::UpTo3);                // or forAdults()

foreach (Nfz::waitingTimes()->search($search)->take(50) as $queue) {   // LazyCollection, pages of 25
    $queue->benefit;                     // "PORADNIA KARDIOLOGICZNA"
    $queue->provider;                    // provider name, ->providerCode, ->providerNip, ->providerRegon
    $queue->place->name;                 // "PORADNIA KARDIOLOGICZNA DLA DZIECI"
    $queue->place->address;              // "DALEKA 11", ->locality, ->county, ->latitude, ->longitude
    $queue->place->bookingPhone();       // registration phone, otherwise the general one
    $queue->place->accessibility->elevator;   // true / false / null (no information)
    $queue->forecast->text;              // predicted waiting time as published, e.g. "14 dni"
    $queue->forecast->days;              // 14
    $queue->forecast->expectedDate();    // CarbonImmutable
    $queue->statistics->awaiting;        // people on the list at the end of the month
    $queue->statistics->averageWaitDays;
}

$page = Nfz::waitingTimes()->searchPage(['benefit' => 'ortoped', 'province' => '12'], page: 2, limit: 25);
$page->total; $page->lastPage(); $page->hasMorePages();

$queue = Nfz::waitingTimes()->queue($id);          // null for an unknown id
$other = Nfz::waitingTimes()->otherPlaces($id);    // the same benefit in other places of the provider

Nfz::waitingTimes()->benefits('kardio');                    // LazyCollection<string>
Nfz::waitingTimes()->localities('krak', province: '06');    // LazyCollection<DictionaryItem>
Nfz::waitingTimes()->counties(province: '06');
Nfz::waitingTimes()->streets('długa', '06', locality: 'KRAKÓW');
Nfz::waitingTimes()->places('poradnia', '06');
Nfz::waitingTimes()->providers('szpital', '06');            // ->code holds the provider code

$agreements = Nfz::contracts()->agreements([
    'year' => 2025,
    'branch' => '06',                 // 
    'updatedSince' => now()->subWeek(),   // updatedSince (date), sort ("attribute:asc|desc")
]);

foreach ($agreements as $agreement) {
    $agreement->code;          // "064/100032/PPZ/08/2025"
    $agreement->serviceName;   // "Programy pilotażowe"
    $agreement->amount;        // "54720.00" (decimal string), ->currency "PLN"
}

$details = Nfz::contracts()->agreement($agreement->id);   // ->plans (product, quantity, price, from, to)
$plan = Nfz::contracts()->plan($details->plans[0]->id);   // ->months, all pages read
$month = Nfz::contracts()->month($plan->months[0]->id);   // ->packages with unit products and weights
$provider = Nfz::contracts()->provider(2025, '064/100032', '06');   // provider with all its contracts

Nfz::contracts()->providers(['year' => 2025, 'branch' => '06']);   // with the yearly total ("amount")
Nfz::contracts()->serviceTypes(2025);                               // "01 Podstawowa Opieka Zdrowotna", ...
Nfz::contracts()->contractProducts(2025, name: 'rehabilitacja');
Nfz::contracts()->orthopedicSupplies(2025);
Nfz::contracts()->availableYears();                                 // [2008, ..., 2026]

use Beziworld\Nfz\Enums\StatisticsApi;

Nfz::statistics(StatisticsApi::PharmacyRefunds)->all('medicine-products', ['name' => 'apap']);   // LazyCollection
Nfz::statistics(StatisticsApi::Benefits)->page('sections', page: 1);
Nfz::statistics(StatisticsApi::DrugPrograms)->get('available-periods');

$check = Nfz::ewus()->check('79060804378');   // validated locally first; nothing is sent for a malformed PESEL

$check->status;             // InsuranceStatus::Insured, NotInsured, NotFound (not in CWU), PeselAnnulled
$check->isInsured();
$check->validUntil;         // day of the confirmation
$check->firstName;          // "ImięTAK", ->lastName, ->fullName()
$check->prescriptionMark;   // "DN" for entitled persons under 18, ->hasDnMark()
$check->additionalInfo;     // list of AdditionalInfo: code ("PESEL-UKR-DOROSLY"), level (Information/Warning), value
$check->operationId;        // "L1712M01200000001"
$check->checkedAt;
$check->document;           // the signed NFZ confirmation (status_cwu_odp XML), cut byte for byte for archiving
$check->maskedPesel();      // "********378", use it in logs

Nfz::ewus()->isInsured($pesel);
Nfz::ewus()->check($pesel, fresh: true);   // ignore the result cached for today

Nfz::ewus()->login();                              // Session: ->messageCode, ->passwordExpiresInDays
Nfz::ewus()->logout();
Nfz::ewus()->changePassword('new password');        // also changes the password in the branch portal
Nfz::ewus()->changeExpiredPassword('new password'); // after login threw PasswordExpired

// config/nfz.php
'ewus' => [
    'connections' => [
        'clinic' => ['domain' => '07', 'login' => '...', 'password' => '...'],
        'lab' => ['domain' => '06', 'operator_type' => 'SWD', 'operator_id' => '...', 'login' => '...', 'password' => '...'],
    ],
],

Nfz::ewus('lab')->check($pesel);

// credentials stored per tenant
Nfz::ewusUsing(['domain' => $tenant->nfz_branch, 'login' => $tenant->ewus_login, 'password' => $tenant->ewus_password])->check($pesel);

use Beziworld\Nfz\Rules\InsuredInNfz;

$request->validate(['pesel' => ['onfirm the entitlement
(new InsuredInNfz())->connection('lab');   // named eWUS connection
bash
php artisan nfz:check-insurance 79060804378               # PESEL masked in the output; exit code 1 when not insured
php artisan nfz:check-insurance 79060804378 --with-name --connection=lab --fresh
php artisan nfz:waiting-times kardiolog --province=mazowieckie --locality=WARSZAWA --urgent --limit=20