From 4dc2a38feabf4797f2b60c38ffe1bb65b742ddd0 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 20:42:56 +0000 Subject: [PATCH] Release v0.1.1 --- client/client.go | 2 - core/client_option.go | 2 +- lab_tests.go | 32 +++ labtests.go | 39 ---- labtests/client.go | 483 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 516 insertions(+), 42 deletions(-) delete mode 100644 labtests.go diff --git a/client/client.go b/client/client.go index 9a125d1..bbd0ef8 100644 --- a/client/client.go +++ b/client/client.go @@ -48,7 +48,6 @@ type Client struct { Team *team.Client Providers *providers.Client Physician *physician.Client - Labtests *labtests.Client LabTests *labtests.Client Order *order.Client AthomePhlebotomy *athomephlebotomy.Client @@ -80,7 +79,6 @@ func NewClient(opts ...core.ClientOption) *Client { Team: team.NewClient(opts...), Providers: providers.NewClient(opts...), Physician: physician.NewClient(opts...), - Labtests: labtests.NewClient(opts...), LabTests: labtests.NewClient(opts...), Order: order.NewClient(opts...), AthomePhlebotomy: athomephlebotomy.NewClient(opts...), diff --git a/core/client_option.go b/core/client_option.go index ebb08fc..53d6871 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.1.0") + headers.Set("X-Fern-SDK-Version", "0.1.1") return headers } diff --git a/lab_tests.go b/lab_tests.go index c28bfa0..aaabc74 100644 --- a/lab_tests.go +++ b/lab_tests.go @@ -16,6 +16,24 @@ type CreateLabTestRequest struct { Fasting *core.Optional[bool] `json:"fasting,omitempty"` } +type CreateOrderRequestCompatible struct { + UserId string `json:"user_id"` + LabTestId string `json:"lab_test_id"` + Physician *core.Optional[PhysicianCreateRequest] `json:"physician,omitempty"` + HealthInsurance *core.Optional[HealthInsuranceCreateRequest] `json:"health_insurance,omitempty"` + // Defines whether order is priority or not. Only available for Labcorp. For Labcorp, this corresponds to a STAT order. + Priority *core.Optional[bool] `json:"priority,omitempty"` + Consents []*Consent `json:"consents,omitempty"` + PatientDetails *PatientDetailsCompatible `json:"patient_details,omitempty"` + PatientAddress *PatientAddressCompatible `json:"patient_address,omitempty"` +} + +type CreateRegistrableTestkitOrderRequest struct { + UserId string `json:"user_id"` + LabTestId string `json:"lab_test_id"` + ShippingDetails *ShippingAddress `json:"shipping_details,omitempty"` +} + type GetMarkersV3LabTestsMarkersGetRequest struct { // The identifier Vital assigned to a lab partner. LabId *int `json:"-"` @@ -24,3 +42,17 @@ type GetMarkersV3LabTestsMarkersGetRequest struct { Page *int `json:"-"` Size *int `json:"-"` } + +type LabTestsGetAreaInfoRequest struct { + // Zip code of the area to check + ZipCode string `json:"-"` +} + +type LabTestsSearchDiagnosisRequest struct { + DiagnosisQuery string `json:"-"` +} + +type PayorSearchRequest struct { + InsuranceName string `json:"insurance_name"` + InsuranceState *core.Optional[string] `json:"insurance_state,omitempty"` +} diff --git a/labtests.go b/labtests.go deleted file mode 100644 index 8a8ae8c..0000000 --- a/labtests.go +++ /dev/null @@ -1,39 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package api - -import ( - core "github.com/fern-vital/vital-go/core" -) - -type CreateOrderRequestCompatible struct { - UserId string `json:"user_id"` - LabTestId string `json:"lab_test_id"` - Physician *core.Optional[PhysicianCreateRequest] `json:"physician,omitempty"` - HealthInsurance *core.Optional[HealthInsuranceCreateRequest] `json:"health_insurance,omitempty"` - // Defines whether order is priority or not. Only available for Labcorp. For Labcorp, this corresponds to a STAT order. - Priority *core.Optional[bool] `json:"priority,omitempty"` - Consents []*Consent `json:"consents,omitempty"` - PatientDetails *PatientDetailsCompatible `json:"patient_details,omitempty"` - PatientAddress *PatientAddressCompatible `json:"patient_address,omitempty"` -} - -type CreateRegistrableTestkitOrderRequest struct { - UserId string `json:"user_id"` - LabTestId string `json:"lab_test_id"` - ShippingDetails *ShippingAddress `json:"shipping_details,omitempty"` -} - -type LabtestsGetAreaInfoRequest struct { - // Zip code of the area to check - ZipCode string `json:"-"` -} - -type LabtestsSearchDiagnosisRequest struct { - DiagnosisQuery string `json:"-"` -} - -type PayorSearchRequest struct { - InsuranceName string `json:"insurance_name"` - InsuranceState *core.Optional[string] `json:"insurance_state,omitempty"` -} diff --git a/labtests/client.go b/labtests/client.go index eedf455..be48a3f 100644 --- a/labtests/client.go +++ b/labtests/client.go @@ -33,6 +33,31 @@ 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) { + 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 +} + func (c *Client) CreateLabTestForTeam(ctx context.Context, request *vitalgo.CreateLabTestRequest) (*vitalgo.ClientFacingLabTest, error) { baseURL := "" if c.baseURL != "" { @@ -161,3 +186,461 @@ func (c *Client) GetLabs(ctx context.Context) ([]*vitalgo.ClientFacingLab, error } 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 { + 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 +} + +// 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) { + baseURL := "" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := baseURL + "/" + "v3/order/area/info" + + 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 + } + + 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 + } + 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 + } + 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 + } + 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 + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/result/metadata", 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.LabResultsMetadata + if err := core.DoRequest( + ctx, + c.httpClient, + endpointURL, + http.MethodGet, + nil, + &response, + false, + c.header, + errorDecoder, + ); err != nil { + return response, err + } + return response, nil +} + +// Return both metadata and raw json test data +func (c *Client) GetResults(ctx context.Context, orderId string) (*vitalgo.LabResultsRaw, error) { + baseURL := "" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := fmt.Sprintf(baseURL+"/"+"v3/order/%v/result", 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.LabResultsRaw + 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 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 + } + return response, nil +}