openehr-rs 0.3.1

A typed asynchronous client for the EHRDB/openEHR REST API.
Documentation
use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer};
use uuid::Uuid;

pub trait ToAql {
    fn to_aql_string(&self) -> String;
}

impl ToAql for Uuid {
    fn to_aql_string(&self) -> String {
        format!("'{}'", self)
    }
}

// impl ToAql for Vec<Uuid> {
//     fn to_aql_string(&self) -> String {
//         let uuid_strings: Vec<String> = self.iter().map(|uuid| format!("'{}'", uuid)).collect();
//         format!("{{ {} }}", uuid_strings.join(", "))
//     }
// }

impl ToAql for DateTime<Utc> {
    fn to_aql_string(&self) -> String {
        format!("'{}'", self.format("%Y-%m-%dT%H:%M:%SZ"))
    }
}

impl ToAql for String {
    fn to_aql_string(&self) -> String {
        format!("'{}'", self)
    }
}

// impl ToAql for Vec<String> {
//     fn to_aql_string(&self) -> String {
//         let formatted_strings: Vec<String> = self.iter().map(|s| format!("'{}'", s)).collect();
//         format!("{{ {} }}", formatted_strings.join(", "))
//     }
// }

impl ToAql for &str {
    fn to_aql_string(&self) -> String {
        format!("'{}'", self)
    }
}

// impl ToAql for Vec<&str> {
//     fn to_aql_string(&self) -> String {
//         let formatted_strings: Vec<String> = self.iter().map(|s| format!("'{}'", s)).collect();
//         format!("{{ {} }}", formatted_strings.join(", "))
//     }
// }

impl<T: ToAql + Sync> ToAql for Vec<T> {
    fn to_aql_string(&self) -> String {
        let formatted_strings: Vec<String> = self.iter().map(|s| s.to_aql_string()).collect();
        format!("{{ {} }}", formatted_strings.join(", "))
    }
}

pub fn deserialize_as_string<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
    D: Deserializer<'de>,
{
    let value = Option::<serde_json::Value>::deserialize(deserializer)?;
    match value {
        Some(val) => Ok(Some(val.to_string())),
        None => Ok(None),
    }
}