pub struct StoredResource { /* private fields */ }Expand description
A FHIR resource with persistence metadata.
StoredResource wraps a FHIR resource (stored as JSON) along with
metadata required for persistence operations:
- Identity: Resource type and ID
- Versioning: Version ID for optimistic locking
- Tenancy: Tenant that owns the resource
- FHIR Version: The FHIR specification version (R4, R4B, R5, R6)
- Timestamps: Creation, modification, and deletion times
- ETag: For HTTP caching and conditional updates
§Examples
use helios_persistence::types::StoredResource;
use helios_persistence::tenant::TenantId;
use helios_fhir::FhirVersion;
use serde_json::json;
let resource = StoredResource::new(
"Patient",
"123",
TenantId::new("acme"),
json!({
"resourceType": "Patient",
"id": "123",
"name": [{"family": "Smith"}]
}),
FhirVersion::default(),
);
assert_eq!(resource.resource_type(), "Patient");
assert_eq!(resource.id(), "123");
assert_eq!(resource.version_id(), "1");Implementations§
Source§impl StoredResource
impl StoredResource
Sourcepub fn new(
resource_type: impl Into<String>,
id: impl Into<String>,
tenant_id: TenantId,
content: Value,
fhir_version: FhirVersion,
) -> Self
pub fn new( resource_type: impl Into<String>, id: impl Into<String>, tenant_id: TenantId, content: Value, fhir_version: FhirVersion, ) -> Self
Creates a new stored resource with the given properties.
This creates a new resource with:
- Version ID set to “1”
- Created and last_modified set to current time
- ETag derived from version ID
Sourcepub fn from_storage(
resource_type: impl Into<String>,
id: impl Into<String>,
version_id: impl Into<String>,
tenant_id: TenantId,
content: Value,
created_at: DateTime<Utc>,
last_modified: DateTime<Utc>,
deleted_at: Option<DateTime<Utc>>,
fhir_version: FhirVersion,
) -> Self
pub fn from_storage( resource_type: impl Into<String>, id: impl Into<String>, version_id: impl Into<String>, tenant_id: TenantId, content: Value, created_at: DateTime<Utc>, last_modified: DateTime<Utc>, deleted_at: Option<DateTime<Utc>>, fhir_version: FhirVersion, ) -> Self
Creates a stored resource from existing data (e.g., loaded from database).
Sourcepub fn resource_type(&self) -> &str
pub fn resource_type(&self) -> &str
Returns the FHIR resource type.
Sourcepub fn version_id(&self) -> &str
pub fn version_id(&self) -> &str
Returns the version ID.
Sourcepub fn fhir_version(&self) -> FhirVersion
pub fn fhir_version(&self) -> FhirVersion
Returns the FHIR specification version of this resource.
Sourcepub fn content_mut(&mut self) -> &mut Value
pub fn content_mut(&mut self) -> &mut Value
Returns a mutable reference to the resource content.
Sourcepub fn into_content(self) -> Value
pub fn into_content(self) -> Value
Consumes self and returns the content.
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Returns when the resource was created.
Sourcepub fn last_modified(&self) -> DateTime<Utc>
pub fn last_modified(&self) -> DateTime<Utc>
Returns when the resource was last modified.
Sourcepub fn deleted_at(&self) -> Option<DateTime<Utc>>
pub fn deleted_at(&self) -> Option<DateTime<Utc>>
Returns when the resource was deleted, if applicable.
Sourcepub fn is_deleted(&self) -> bool
pub fn is_deleted(&self) -> bool
Returns true if the resource has been deleted.
Sourcepub fn method(&self) -> Option<ResourceMethod>
pub fn method(&self) -> Option<ResourceMethod>
Returns the HTTP method that created this version.
Sourcepub fn versioned_url(&self) -> String
pub fn versioned_url(&self) -> String
Returns the versioned URL path (e.g., “Patient/123/_history/1”).
Sourcepub fn new_version(self, content: Value, method: ResourceMethod) -> Self
pub fn new_version(self, content: Value, method: ResourceMethod) -> Self
Creates a new version of this resource with updated content.
The new version will have:
- Incremented version ID
- Updated last_modified timestamp
- New ETag
- Same FHIR version as the original
Sourcepub fn mark_deleted(self) -> Self
pub fn mark_deleted(self) -> Self
Marks this resource as deleted.
Creates a new version with the deleted_at timestamp set.
Sourcepub fn matches_etag(&self, etag: &str) -> bool
pub fn matches_etag(&self, etag: &str) -> bool
Checks if the given ETag matches this resource’s ETag.
Used for If-Match conditional updates.
Sourcepub fn meta(&self) -> ResourceMeta
pub fn meta(&self) -> ResourceMeta
Returns the FHIR Meta element for this resource.
Trait Implementations§
Source§impl Clone for StoredResource
impl Clone for StoredResource
Source§fn clone(&self) -> StoredResource
fn clone(&self) -> StoredResource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StoredResource
impl Debug for StoredResource
Source§impl<'de> Deserialize<'de> for StoredResource
impl<'de> Deserialize<'de> for StoredResource
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for StoredResource
impl RefUnwindSafe for StoredResource
impl Send for StoredResource
impl Sync for StoredResource
impl Unpin for StoredResource
impl UnsafeUnpin for StoredResource
impl UnwindSafe for StoredResource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.