fhir-sdk
fhir-sdk copied to clipboard
Chrono feature
Hi, Would you be up to include in the sdk a chrono feature flag?
This flag could map from FHIR Date, DateTime, Instant... etc into chrono counterparts. Would you be willing to integrate something like that if I contribute to the repo?
You mean conversion implementations to/from chrono?
Like time, chrono will probably also not be able to differentiate between "2024" and "2024-01-01", if it can even save just 2024. So it is a bit unclear how conversion should work. It could probably work to make a similar struct, but using chrono instead of time. Maybe it is even possible to make it generic and support both in the same struct? In that case the resources would choose the time implementation, but it could convert itself to the other via methods whenever you access a field. And it would be simpler to switch out when one of them becomes unmaintained again :D
So, in general, I would accept chrono integration. Though could you outline what exactly you are planning? Something like FHIR-DateTime to chrono::DateTime while rounding 2024 tp 2024-01-01 might not be universal and application dependent, so that would not something that makes sense in this library I think
Maybe create an Enum fhir_sdk::chrono::Chrono
enum Chrono {
DateTime(chrono:DateTime<Utc>),
NaiveDate(chrono:NaiveDate),
Date(fhir_model::Date)
}
And create the mappings for fhir_model::Date and fhir_model::DateTime into this this new Chrono enum. YYYY or YYYY-MM could be kept as fhir_model:Date since those will never be mappable into chrono, and everything else should have a counter part in chrono as NaiveDate or DateTime.
That's my guess but maybe this is going to get more clear during implementation.
Yeah that makes sense. The date would "conflict" or rather confuse though, as it still has the time::Date variant. Do you think it is possible to actually make something conceptually similar to this:
// In some module.
pub enum DateTime<T> {
DateTime(Instant<T>),
Date(Date<T>),
}
pub enum Date<T> {
Date(T),
YearMonth(..),
Year(..),
}
impl DateTime<OffsetDateTime> {
pub fn into_chrono(self) -> DateTime<chrono::DateTime> { .. }
}
// Where DateTime is currently defined/lib.rs.
pub type DateTime = crate::datetime::DateTime<OffsetDateTime>;
I think that might even be less work, is a nice API and allow more future possibilities.