From bc3acacd39e35dcc5713eda9e64a526eacbb7515 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 20:26:55 +0000 Subject: [PATCH] Release v0.1.0 --- core/client_option.go | 2 +- labtests/client.go | 396 +++--------------------------------------- 2 files changed, 22 insertions(+), 376 deletions(-) diff --git a/core/client_option.go b/core/client_option.go index 958ea5f..ebb08fc 100644 --- a/core/client_option.go +++ b/core/client_option.go @@ -36,6 +36,6 @@ func (c *ClientOptions) cloneHeader() http.Header { headers := c.HTTPHeader.Clone() headers.Set("X-Fern-Language", "Go") headers.Set("X-Fern-SDK-Name", "github.com/fern-vital/vital-go") - headers.Set("X-Fern-SDK-Version", "0.0.7") + headers.Set("X-Fern-SDK-Version", "0.1.0") return headers } diff --git a/labtests/client.go b/labtests/client.go index d14d203..eedf455 100644 --- a/labtests/client.go +++ b/labtests/client.go @@ -33,39 +33,13 @@ func NewClient(opts ...core.ClientOption) *Client { } } -// GET all the lab tests the team has access to. -func (c *Client) GetTests(ctx context.Context) ([]*vitalgo.ClientFacingLabTest, error) { +func (c *Client) CreateLabTestForTeam(ctx context.Context, request *vitalgo.CreateLabTestRequest) (*vitalgo.ClientFacingLabTest, error) { baseURL := "" if c.baseURL != "" { baseURL = c.baseURL } endpointURL := baseURL + "/" + "v3/lab_tests" - var response []*vitalgo.ClientFacingLabTest - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, - nil, - &response, - false, - c.header, - nil, - ); err != nil { - return response, err - } - return response, nil -} - -// Creates an order for an unregistered testkit -func (c *Client) CreateUnregisteredTestkitOrder(ctx context.Context, request *vitalgo.CreateRegistrableTestkitOrderRequest) (*vitalgo.PostOrderResponse, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := baseURL + "/" + "v3/order/testkit" - errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) if err != nil { @@ -85,7 +59,7 @@ func (c *Client) CreateUnregisteredTestkitOrder(ctx context.Context, request *vi return apiError } - var response *vitalgo.PostOrderResponse + var response *vitalgo.ClientFacingLabTest if err := core.DoRequest( ctx, c.httpClient, @@ -102,111 +76,30 @@ func (c *Client) CreateUnregisteredTestkitOrder(ctx context.Context, request *vi return response, nil } -// GET information about an area with respect to lab-testing. -// -// Information returned: -// * Whether a given zip code is served by our Phlebotomy network. -func (c *Client) GetAreaInfo(ctx context.Context, request *vitalgo.LabtestsGetAreaInfoRequest) (*vitalgo.AreaInfo, error) { +// GET all the markers for the given lab. +func (c *Client) GetMarkers(ctx context.Context, request *vitalgo.GetMarkersV3LabTestsMarkersGetRequest) (*vitalgo.GetMarkersResponse, error) { baseURL := "" if c.baseURL != "" { baseURL = c.baseURL } - endpointURL := baseURL + "/" + "v3/order/area/info" + endpointURL := baseURL + "/" + "v3/lab_tests/markers" queryParams := make(url.Values) - queryParams.Add("zip_code", fmt.Sprintf("%v", request.ZipCode)) - if len(queryParams) > 0 { - endpointURL += "?" + queryParams.Encode() - } - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError + if request.LabId != nil { + queryParams.Add("lab_id", fmt.Sprintf("%v", *request.LabId)) } - - var response *vitalgo.AreaInfo - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, - request, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err + if request.Name != nil { + queryParams.Add("name", fmt.Sprintf("%v", *request.Name)) } - return response, nil -} - -// This endpoint returns the lab results for the order. -func (c *Client) GetResultsPdf(ctx context.Context, orderId string) (any, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL + if request.Page != nil { + queryParams.Add("page", fmt.Sprintf("%v", *request.Page)) } - endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/result/pdf", orderId) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response any - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, - nil, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err + if request.Size != nil { + queryParams.Add("size", fmt.Sprintf("%v", *request.Size)) } - return response, nil -} - -// Return metadata related to order results, such as lab metadata, -// provider and sample dates. -func (c *Client) GetResultsMetadata(ctx context.Context, orderId string) (*vitalgo.LabResultsMetadata, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL + if len(queryParams) > 0 { + endpointURL += "?" + queryParams.Encode() } - endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/result/metadata", orderId) errorDecoder := func(statusCode int, body io.Reader) error { raw, err := io.ReadAll(body) @@ -227,13 +120,13 @@ func (c *Client) GetResultsMetadata(ctx context.Context, orderId string) (*vital return apiError } - var response *vitalgo.LabResultsMetadata + var response *vitalgo.GetMarkersResponse if err := core.DoRequest( ctx, c.httpClient, endpointURL, http.MethodGet, - nil, + request, &response, false, c.header, @@ -244,34 +137,15 @@ func (c *Client) GetResultsMetadata(ctx context.Context, orderId string) (*vital return response, nil } -// Return both metadata and raw json test data -func (c *Client) GetResults(ctx context.Context, orderId string) (*vitalgo.LabResultsRaw, error) { +// GET all the labs. +func (c *Client) GetLabs(ctx context.Context) ([]*vitalgo.ClientFacingLab, error) { baseURL := "" if c.baseURL != "" { baseURL = c.baseURL } - endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/result", orderId) + endpointURL := baseURL + "/" + "v3/lab_tests/labs" - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response *vitalgo.LabResultsRaw + var response []*vitalgo.ClientFacingLab if err := core.DoRequest( ctx, c.httpClient, @@ -281,235 +155,7 @@ func (c *Client) GetResults(ctx context.Context, orderId string) (*vitalgo.LabRe &response, false, c.header, - errorDecoder, - ); err != nil { - return response, err - } - return response, nil -} - -// GET requisition pdf for an order -// -// Your Order ID. -func (c *Client) Get(ctx context.Context, orderId string) (any, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/requisition/pdf", orderId) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response any - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, nil, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err - } - return response, nil -} - -// GET individual order by ID. -// -// Your Order ID. -func (c *Client) GetOrder(ctx context.Context, orderId string) (*vitalgo.ClientFacingOrder, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v", orderId) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response *vitalgo.ClientFacingOrder - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, - nil, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err - } - return response, nil -} - -// POST create new order -func (c *Client) CreateOrder(ctx context.Context, request *vitalgo.CreateOrderRequestCompatible) (*vitalgo.PostOrderResponse, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := baseURL + "/" + "v3/order" - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response *vitalgo.PostOrderResponse - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodPost, - request, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err - } - return response, nil -} - -func (c *Client) SearchPayor(ctx context.Context, request *vitalgo.PayorSearchRequest) ([]*vitalgo.ClientFacingPayorSearchResponse, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := baseURL + "/" + "v3/insurance/search/payor" - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response []*vitalgo.ClientFacingPayorSearchResponse - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodPost, - request, - &response, - false, - c.header, - errorDecoder, - ); err != nil { - return response, err - } - return response, nil -} - -func (c *Client) SearchDiagnosis(ctx context.Context, request *vitalgo.LabtestsSearchDiagnosisRequest) ([]*vitalgo.ClientFacingDiagnosisInformation, error) { - baseURL := "" - if c.baseURL != "" { - baseURL = c.baseURL - } - endpointURL := baseURL + "/" + "v3/insurance/search/diagnosis" - - queryParams := make(url.Values) - queryParams.Add("diagnosis_query", fmt.Sprintf("%v", request.DiagnosisQuery)) - if len(queryParams) > 0 { - endpointURL += "?" + queryParams.Encode() - } - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 422: - value := new(vitalgo.UnprocessableEntityError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError - } - return value - } - return apiError - } - - var response []*vitalgo.ClientFacingDiagnosisInformation - if err := core.DoRequest( - ctx, - c.httpClient, - endpointURL, - http.MethodGet, - request, - &response, - false, - c.header, - errorDecoder, ); err != nil { return response, err }