autogen-stedi 0.3.2

Auto-generated, strongly-typed Rust client for the Stedi APIs
Documentation
/*
 * Stedi Payers
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 2024-04-01
 * Contact: healthcare@stedi.com
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::payers::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`get_payer_record`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPayerRecordError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_payer_records`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPayerRecordsError {
    Status400(models::ValidationExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_payer_records_csv`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPayerRecordsCsvError {
    Status400(models::ValidationExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`search_payers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchPayersError {
    Status400(models::ValidationExceptionResponseContent),
    Status401(models::UnauthorizedExceptionResponseContent),
    Status404(models::ResourceNotFoundExceptionResponseContent),
    Status500(models::InternalFailureExceptionResponseContent),
    UnknownValue(serde_json::Value),
}


/// Retrieve a single payer record by its Stedi payer ID.
pub async fn get_payer_record(configuration: &configuration::Configuration, stedi_id: &str) -> Result<models::GetPayerRecordResponseContent, Error<GetPayerRecordError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_stedi_id = stedi_id;

    let uri_str = format!("{}/payer/{stediId}", configuration.base_path, stediId=crate::payers::apis::urlencode(p_path_stedi_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPayerRecordResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetPayerRecordResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetPayerRecordError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// List Stedi's supported payers in JSON format
pub async fn list_payer_records(configuration: &configuration::Configuration, page_size: Option<i32>, page_token: Option<&str>) -> Result<models::ListPayerRecordsResponseContent, Error<ListPayerRecordsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_page_size = page_size;
    let p_query_page_token = page_token;

    let uri_str = format!("{}/payers", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_token {
        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPayerRecordsResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListPayerRecordsResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListPayerRecordsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// List Stedi's supported payers in CSV format
pub async fn list_payer_records_csv(configuration: &configuration::Configuration, ) -> Result<String, Error<ListPayerRecordsCsvError>> {

    let uri_str = format!("{}/payers/csv", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Ok(content),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListPayerRecordsCsvError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Search for payers by name, ID, or alias.
pub async fn search_payers(configuration: &configuration::Configuration, page_size: Option<i32>, page_token: Option<&str>, query: Option<&str>, eligibility_check: Option<models::TransactionFilterValue>, claim_status: Option<models::TransactionFilterValue>, professional_claim_submission: Option<models::TransactionFilterValue>, dental_claim_submission: Option<models::TransactionFilterValue>, institutional_claim_submission: Option<models::TransactionFilterValue>, claim_payment: Option<models::TransactionFilterValue>, coordination_of_benefits: Option<models::TransactionFilterValue>, unsolicited_claim_attachment: Option<models::TransactionFilterValue>, coverage_types: Option<Vec<models::CoverageType>>, operating_states: Option<Vec<models::OperatingStateCode>>, programs: Option<Vec<models::Program>>) -> Result<models::SearchPayersResponseContent, Error<SearchPayersError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_page_size = page_size;
    let p_query_page_token = page_token;
    let p_query_query = query;
    let p_query_eligibility_check = eligibility_check;
    let p_query_claim_status = claim_status;
    let p_query_professional_claim_submission = professional_claim_submission;
    let p_query_dental_claim_submission = dental_claim_submission;
    let p_query_institutional_claim_submission = institutional_claim_submission;
    let p_query_claim_payment = claim_payment;
    let p_query_coordination_of_benefits = coordination_of_benefits;
    let p_query_unsolicited_claim_attachment = unsolicited_claim_attachment;
    let p_query_coverage_types = coverage_types;
    let p_query_operating_states = operating_states;
    let p_query_programs = programs;

    let uri_str = format!("{}/payers/search", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_token {
        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_query {
        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_eligibility_check {
        req_builder = req_builder.query(&[("eligibilityCheck", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_claim_status {
        req_builder = req_builder.query(&[("claimStatus", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_professional_claim_submission {
        req_builder = req_builder.query(&[("professionalClaimSubmission", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_dental_claim_submission {
        req_builder = req_builder.query(&[("dentalClaimSubmission", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_institutional_claim_submission {
        req_builder = req_builder.query(&[("institutionalClaimSubmission", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_claim_payment {
        req_builder = req_builder.query(&[("claimPayment", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_coordination_of_benefits {
        req_builder = req_builder.query(&[("coordinationOfBenefits", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_unsolicited_claim_attachment {
        req_builder = req_builder.query(&[("unsolicitedClaimAttachment", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_coverage_types {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("coverageTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("coverageTypes", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref param_value) = p_query_operating_states {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("operatingStates".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("operatingStates", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref param_value) = p_query_programs {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("programs".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("programs", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("Authorization", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchPayersResponseContent`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SearchPayersResponseContent`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SearchPayersError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}