Logo Lanfrica

HISP-Uganda/go-dhis2-sdk

Domain:

healthcare

Record type:

software
Creator:
HIS
Host:
# 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 …