#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod codes;
pub mod observation;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SatuSehatEnv {
Sandbox,
Production,
}
impl SatuSehatEnv {
pub fn fhir_base_url(&self) -> &'static str {
match self {
Self::Sandbox => "https://api-satusehat-stg.dto.kemkes.go.id/fhir-r4/v1",
Self::Production => "https://api-satusehat.kemkes.go.id/fhir-r4/v1",
}
}
pub fn auth_url(&self) -> &'static str {
match self {
Self::Sandbox => "https://api-satusehat-stg.dto.kemkes.go.id/oauth2/v1/accesstoken",
Self::Production => "https://api-satusehat.kemkes.go.id/oauth2/v1/accesstoken",
}
}
}
#[derive(Debug, Clone)]
pub struct SatuSehatConfig {
pub env: SatuSehatEnv,
pub client_id: String,
pub client_secret: String,
pub organization_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccessToken {
pub access_token: String,
pub token_type: String,
pub expires_in: u64,
}
#[derive(Debug)]
pub enum SatuSehatError {
Json(serde_json::Error),
MissingField(String),
#[cfg(feature = "client")]
Http(reqwest::Error),
}
impl std::fmt::Display for SatuSehatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Json(e) => write!(f, "JSON error: {e}"),
Self::MissingField(s) => write!(f, "Missing required field: {s}"),
#[cfg(feature = "client")]
Self::Http(e) => write!(f, "HTTP error: {e}"),
}
}
}
impl std::error::Error for SatuSehatError {}
impl From<serde_json::Error> for SatuSehatError {
fn from(e: serde_json::Error) -> Self {
Self::Json(e)
}
}