TBJ.Integrations.NFZ.UmwApi 1.0.1

dotnet add package TBJ.Integrations.NFZ.UmwApi --version 1.0.1
                    
NuGet\Install-Package TBJ.Integrations.NFZ.UmwApi -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TBJ.Integrations.NFZ.UmwApi" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TBJ.Integrations.NFZ.UmwApi" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TBJ.Integrations.NFZ.UmwApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TBJ.Integrations.NFZ.UmwApi --version 1.0.1
                    
#r "nuget: TBJ.Integrations.NFZ.UmwApi, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TBJ.Integrations.NFZ.UmwApi@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TBJ.Integrations.NFZ.UmwApi&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TBJ.Integrations.NFZ.UmwApi&version=1.0.1
                    
Install as a Cake Tool

TBJ.Integrations.NFZ.UmwApi

build NuGet

Typowany klient .NET 8, 9, 10 dla publicznego API umów NFZ (app-umw-api).

Pakiet dostarcza async klientów HTTP do pobierania danych o umowach, planach, środkach ortopedycznych, produktach kontraktowych, rodzajach świadczeń, świadczeniodawcach oraz dostępnych latach danych. API NFZ jest publiczne i nie wymaga uwierzytelniania.

Spis treści

Wymagania

  • .NET 8, 9 lub 10
  • Dostęp do internetu (publiczne API NFZ — bez klucza API)

Instalacja

dotnet add package TBJ.Integrations.NFZ.UmwApi

Rejestracja w DI

builder.Services.AddNfzUmwApi(builder.Configuration);
{
  "NfzUmwApi": {
    "BaseUrl": "https://api.nfz.gov.pl/app-umw-api",
    "Timeout": "00:00:30",
    "DictionaryCacheTtl": "24:00:00",
    "DictionaryCacheSizeLimit": 5000
  }
}

Możesz też skonfigurować klienta inline:

builder.Services.AddNfzUmwApi(opt =>
{
    opt.BaseUrl = "https://api.nfz.gov.pl/app-umw-api";
    opt.Timeout = TimeSpan.FromSeconds(30);
    opt.DictionaryCacheTtl = TimeSpan.FromHours(24);
    opt.DictionaryCacheSizeLimit = 5000;
});

Klienci

Klient Odpowiedzialność
IAgreementsClient Umowy, plany, miesięczne plany
IDictionariesClient Produkty kontraktowe, środki ortopedyczne, rodzaje świadczeń, świadczeniodawcy
IInfoClient Dostępne lata danych

Paginacja i strumieniowanie

Metody GetPageAsync zwracają stronę wyników wraz z całkowitą liczbą rekordów. Metody GetAllAsync zwracają IAsyncEnumerable<T> i automatycznie przechodzą przez wszystkie strony:

await foreach (var agreement in agreements.GetAllAsync(new GetAgreementsRequest
{
    Branch = "01",
    Year = 2024
}))
{
    Console.WriteLine(agreement.Attributes?.ProviderName);
}

Przykłady użycia

public class NfzService(IAgreementsClient agreements, IDictionariesClient dictionaries)
{
    public async Task ShowAgreementsAsync(string branch, int year)
    {
        var page = await agreements.GetPageAsync(new GetAgreementsRequest
        {
            Branch = branch,
            Year = year
        });

        Console.WriteLine($"Znaleziono {page.TotalCount} umów");

        await foreach (var agreement in agreements.GetAllAsync(new GetAgreementsRequest
        {
            Branch = branch,
            Year = year
        }))
        {
            Console.WriteLine(agreement.Attributes?.ProviderName);
        }
    }
}

Szczegółową dokumentację i dodatkowe przykłady znajdziesz w folderze docs/TBJ.Integrations.NFZ.UmwApi.

Obsługa błędów

Wszystkie błędy HTTP oraz błędy semantyczne API NFZ są konwertowane do wyjątku NfzApiException.

try
{
    var detail = await agreements.GetDetailAsync(new GetAgreementDetailRequest { Id = "nieistniejące-id" });
}
catch (NfzApiException ex)
{
    Console.WriteLine($"HTTP {ex.HttpStatusCode}: {ex.Message}");
}

Cykl życia serwisów

Serwis Lifetime Uzasadnienie
IAgreementsClient Scoped Per-request
IDictionariesClient Scoped Per-request, korzysta z cache
IInfoClient Scoped Per-request, korzysta z cache
IMemoryCache Singleton Współdzielony cache słowników
HttpClient przez IHttpClientFactory Automatyczna rotacja handlerów

Wersjonowanie i publikacja

Projekt używa MinVer do automatycznego wersjonowania przez tagi Git.

git tag nfz-umwapi/v1.0.1
git push origin nfz-umwapi/v1.0.1

Wypchnięcie tagu uruchamia workflow release.yml, który publikuje paczkę na NuGet.org (Trusted Publishing) oraz GitHub Packages i tworzy zamrożoną gałąź release/nfz-umwapi/1.0.1.

Wymagane sekrety w ustawieniach repozytorium: NUGET_USER oraz RELEASE_PAT.

Repozytorium i paczka

Licencja

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 131 7/4/2026
1.0.0 111 7/4/2026