Logo Lanfrica

HISP-Uganda/go-dhis2-sdk

Domaine:

healthcare

Type de record:

software
Créateur:
HIS
Hôte:
# DHIS2 Go SDK This is a Go-based SDK for interacting with the DHIS2 Web API, supporting: - Tracker and Aggregate payloads - Query parameter construction - Typed request and response models - Structured error handling - Auto-generated schema models from DHIS2's OpenAPI spec --- ## 📦 Package Structure ```text dhis2/ ├── client.go # HTTP client using Resty ├── query/ # Chainable query param builder ├── response/ # Response summaries (e.g. import status) ├── error/ # Custom DHIS2-aware error types ├── schema/ # Auto-generated models (Event, TEI, etc.) ├── generate-schema.sh # Rebuild schema/ using OpenAPI spec ``` --- ## ✅ Getting Started ### Installation ```bash go get github.com ``` ### Example Usage ```go package main import ( "log" "github.com" "github.com" ) func main() { client := dhis2.NewClient("your-dhis2.org", "admin", "district") event := &schema.Event{ Program: "abc123", OrgUnit: "xyz789", Status: "ACTIVE", } resp, err := client.Post("/api/events", event) if err != nil { log.Fatalf("Error: %v", err) } log.Println("✅ Submitted event successfully:", resp.Status()) } ``` --- ## 🧱 Schema Models (`schema/`) The `schema/` package contains Go types auto-generated from DHIS2's OpenAPI spec (v40+). Only the models listed in `models.txt` are retained and cleaned. Each model file is: - Formatted with `goimports` or `gofmt` - Version-controlled and reproducible --- ## ⚙️ Regenerating Models To regenerate the schema types after a DHIS2 upgrade: ```bash ./generate-schema.sh ``` This will: 1. Download the latest OpenAPI spec 2. Generate all models 3. Retain only models listed in `models.txt` 4. Rename and format `.go` files --- ## 🧰 Dependencies - Go 1.19+ - Resty - `goimports` (optional but recommended) Install dependencies: ```bash go install golang.org