lapro

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 13 Imported by: 0

README

LAPro Go Client

A Go client library for the Lead Advantage Pro (LAPro) API, providing access to Medicare insurance quotes, drug information, pharmacy locations, and geographical data.

Features

  • Authentication: Automatic OAuth2 token management with refresh
  • Drug Information: Search for drug names and dosages
  • Pharmacy Lookup: Find pharmacies by zip code and radius
  • Geographic Data: Retrieve counties by zip code
  • Insurance Quotes: Request Medicare Part D and Medicare Advantage quotes
  • Carrier Information: Get insurance carrier details
  • Custom Types: Built-in support for currency (Cent) and boolean unmarshaling

Installation

go get github.com/medicareschoolcom/lapro

Quick Start

package main

import (
    "context"
    "fmt"
    "net/http"

    "github.com/medicareschoolcom/lapro"
)

func main() {
    client := lapro.NewClient(
        "your-username",
        "your-password",
        "your-client-id",
        "your-client-secret",
        &http.Client{},
    )

    ctx := context.Background()

    // Check client health
    if err := client.Ping(ctx); err != nil {
        fmt.Printf("Client health check failed: %v\n", err)
        return
    }

    // Get counties for a zip code
    counties, err := client.ListCountiesByZipCode(ctx, "90210")
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    fmt.Printf("Found %d state(s) for zip code 90210\n", len(counties))
}

API Methods

Authentication
  • Ping(ctx) - Health check that verifies authentication
Geographic Data
  • ListCountiesByZipCode(ctx, zipCode) - Get counties by zip code
Drug Information
  • GetDrugNames(ctx, searchTerm) - Search drug names by partial match
  • ListDrugDosagesByDrugName(ctx, drugName) - Get dosages for a drug
Pharmacy Lookup
  • ListPharmaciesByZipCode(ctx, zipCode, radius) - Find pharmacies within radius
Insurance Quotes
  • RequestQuote(ctx, params) - Request Medicare insurance quotes
Carrier Information
  • GetCarrier(ctx, carrierID) - Get insurance carrier details

Data Types

Custom Types

The library includes custom types for proper JSON unmarshaling:

  • Boolean - Handles non-standard boolean representations ("yes"/"no", "1"/"0")
  • Cent - Converts currency strings to integer cents for precise calculations
Core Structures
  • Drug - Drug information including NDC codes, strengths, and dosages
  • Pharmacy - Pharmacy details with location and contact information
  • Quote - Insurance quote with premiums and cost estimates
  • County - Geographic county information with FIPS codes

Error Handling

The client returns lapro.ErrNoResults when API calls succeed but return no data. Other errors include detailed API response information.

counties, err := client.ListCountiesByZipCode(ctx, "00000")
if err != nil {
    if errors.Is(err, lapro.ErrNoResults) {
        fmt.Println("No counties found for this zip code")
    } else {
        fmt.Printf("API error: %v\n", err)
    }
}

Testing

The library includes comprehensive integration tests. Set the following environment variables to run tests:

export TEST_LAPRO_USERNAME="your-test-username"
export TEST_LAPRO_PASSWORD="your-test-password"
export TEST_LAPRO_CLIENT_ID="your-test-client-id"
export TEST_LAPRO_CLIENT_SECRET="your-test-client-secret"

go test -v

Thread Safety

The client is thread-safe. Access tokens are automatically managed with proper mutex protection for concurrent usage.

License

See LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	GenderMale   = "M"
	GenderFemale = "F"
)

Variables

View Source
var (
	ErrNoResults = errors.New("no results")
)

Functions

This section is empty.

Types

type Boolean

type Boolean bool

Boolean is a custom type assisting in the proper unmarshaling of non-standard boolean types sent over json.

func (*Boolean) UnmarshalJSON

func (bit *Boolean) UnmarshalJSON(data []byte) error

type Carrier

type Carrier struct {
	CarrierID string `json:"carrier_id"`
	CompanyID string `json:"company_id"`
	ShortName string `json:"short_name"`
	Name      string `json:"name"`
	Active    string `json:"active"`
	NAIC      string `json:"naic"`
}

type Cent

type Cent int32

Cent is a custom type for unmarshaling currency strings into int32 cents.

func (*Cent) UnmarshalJSON

func (c *Cent) UnmarshalJSON(data []byte) error

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(username, password, clientID, clientSecret string, httpClient *http.Client) *Client

func (*Client) GetCarrier

func (c *Client) GetCarrier(ctx context.Context, id int32) (*Carrier, error)

func (*Client) GetDrugNames

func (c *Client) GetDrugNames(ctx context.Context, searchTerm string) ([]*GetDrugNamesResponse, error)

GetDrugNames returns a list of drug names that match the provided partial drug name. A partial drug name typically consist of the first 3 letters of the drug name.

func (*Client) ListCountiesByZipCode

func (c *Client) ListCountiesByZipCode(ctx context.Context, zipCode string) ([]*ListCountiesByZipCodeResponse, error)

ListCountiesByZipCode retrieves all counties within a given zip code, organized by state. The response includes one entry per state that intersects with the zip code, with each state entry containing its respective counties that fall within the zip code boundaries.

func (*Client) ListDrugDosagesByDrugName

func (c *Client) ListDrugDosagesByDrugName(ctx context.Context, drugName string) ([]*Drug, error)

ListDrugDosagesByDrugName returns a list of Drugs & dosages for a given drug name.

func (*Client) ListPharmaciesByZipCode

func (c *Client) ListPharmaciesByZipCode(ctx context.Context, zipCode, radius string) ([]*Pharmacy, error)

ListPharmaciesByZipCode returns a list of pharmacies for a given zipcode, within a given radius from the geographical center of the zipcode.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks the current health status of the client. A client with an active access token is in a healthy state.

func (*Client) RequestQuote

func (c *Client) RequestQuote(ctx context.Context, params RequestQuoteParams) (*RequestQuoteResponse, error)

type County

type County struct {
	Name string `json:"county_name"`
	Fips string `json:"county_fips"`
}

type Drug

type Drug struct {
	DosageID             string  `json:"dosageid"`
	PackType             string  `json:"packtype"`
	Unit                 string  `json:"unit"`
	NDCCode              string  `json:"ndccode"`
	CommonMetricQuantity string  `json:"commonmetricquantity"`
	Strength             string  `json:"strength"`
	TradeName            string  `json:"tradename"`
	DrugName             string  `json:"drugname"`
	DrugID               string  `json:"drugid"`
	IsCommonDosage       Boolean `json:"iscommondosage"`
	DrugType             string  `json:"drugtype"`
	GenericDrugName      string  `json:"genericdrugname"`
	PackSize             string  `json:"packsize"`
	GenericDosageID      string  `json:"genericdosageid"`
	GenericDrugID        string  `json:"genericdrugid"`
	CommonDaysOfSupply   string  `json:"commondaysofsupply"`
	CommonUserQuantity   string  `json:"commonuserquantity"`
}

type Error

type Error struct {
	Message      string          `json:"message"`
	Success      string          `json:"success"`
	StatusCode   string          `json:"statuscode"`
	HTTPMethod   string          `json:"httpmethod"`
	HTTPContent  json.RawMessage `json:"httpcontent"`
	CurrentEvent string          `json:"currentevent"`
}

Error represents an error response from the LAPro API. The structure varies based on the type of error: For successful API calls that return no results (e.g., valid searches with zero records), only the Result, Message, and Success fields are populated. For actual API errors, all fields are populated with the status code indicating the issue type and the complete error response details.

func (Error) Error

func (e Error) Error() string

type ExternalProvider

type ExternalProvider struct {
	ExternalProviderTypeID     string `json:"external_provider_type_id"`
	ExternalProviderID         string `json:"external_provider_id"`
	ExternalProviderLocationID string `json:"external_provider_location_id"`
}

type GetDrugNamesResponse

type GetDrugNamesResponse struct {
	DrugName string `json:"drug_name"`
	DrugID   string `json:"drug_id"`
}

type ListCountiesByZipCodeResponse

type ListCountiesByZipCodeResponse struct {
	StateID   string   `json:"state_id"`
	StateName string   `json:"state_name"`
	Counties  []County `json:"counties"`
}

type Pharmacy

type Pharmacy struct {
	PharmacyID string `json:"pharmacyid"`
	Name       string `json:"name"`
	Distance   string `json:"distance"`
	Address1   string `json:"address1"`
	Address2   string `json:"address2"`
	City       string `json:"city"`
	State      string `json:"state"`
	Zip        string `json:"zip"`
}

type Quote

type Quote struct {
	PlanID                       string `json:"plan_id"`
	PlanName                     string `json:"plan_name"`
	CarrierName                  string `json:"carrier_name"`
	CarrierID                    string `json:"carrier_id"`
	DrugPremiumCents             Cent   `json:"drug_premium"`
	EstimatedAnnualDrugCostCents Cent   `json:"estimated_annual_drug_cost"`
	MAPDProductType              string `json:"mapd_product_type"`
	AnnualTotalCombinedCents     Cent   `json:"annual_total_combined"`
}

func (*Quote) EstimatedMonthlyDrugCostCents

func (q *Quote) EstimatedMonthlyDrugCostCents() Cent

type QuoteDrug

type QuoteDrug struct {
	Name             string `json:"drug_name"`
	Type             string `json:"drug_type"`
	MetricQty        string `json:"drug_metric_qty"`
	Freq             string `json:"drug_freq"`
	NDCCode          string `json:"drug_ndc_code"`
	Strength         string `json:"drug_strength"`
	PackSize         string `json:"drug_pack_size"`
	PackType         string `json:"drug_pack_type"`
	PackUnit         string `json:"drug_pack_unit"`
	DosageExternalID string `json:"drug_dosage_external_id"`
}

type QuoteProducts

type QuoteProducts struct {
	PartD             bool `json:"partd"`
	MedicareAdvantage bool `json:"ma"`
	MAPD              bool `json:"mapd"`
}

type RequestQuoteParams

type RequestQuoteParams struct {
	Zip               string             `json:"zip"`
	County            string             `json:"county"`
	DOB               string             `json:"dob"`
	EffectiveDate     string             `json:"eff_date"`
	HealthStatus      string             `json:"health_status"`
	QuoteProducts     QuoteProducts      `json:"quote_products"`
	ExternalProviders []ExternalProvider `json:"external_providers"`
	Drugs             []QuoteDrug        `json:"drugs"`
	Gender            string             `json:"gender"`
	PharmacyID        string             `json:"pharmacy_id"`
}

type RequestQuoteResponse

type RequestQuoteResponse struct {
	MapDResults []*Quote `json:"mapdresult"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL