pub struct DemographicsService<S> { /* private fields */ }Expand description
Service for managing patient demographics operations.
Uses type-state pattern to enforce correct usage at compile time.
Generic parameter S is either Uninitialised or Initialised.
This service handles creation, updates, and listing of patient demographic records. All operations are version-controlled via Git repositories in each patient’s directory.
Implementations§
Source§impl DemographicsService<Uninitialised>
impl DemographicsService<Uninitialised>
Sourcepub fn new(cfg: Arc<CoreConfig>) -> Self
pub fn new(cfg: Arc<CoreConfig>) -> Self
Creates a new demographics service in the uninitialised state.
§Arguments
cfg- Core configuration containing patient data directory paths
Source§impl DemographicsService<Uninitialised>
impl DemographicsService<Uninitialised>
Sourcepub fn initialise(
self,
author: Author,
care_location: NonEmptyText,
) -> PatientResult<DemographicsService<Initialised>>
pub fn initialise( self, author: Author, care_location: NonEmptyText, ) -> PatientResult<DemographicsService<Initialised>>
Initialises a new patient demographics record.
Creates a new patient with a unique UUID, stores the initial demographics in a YAML file within a sharded directory structure, and initialises a Git repository for version control.
This method consumes self and returns a new DemographicsService<Initialised> on success,
enforcing at compile time that you cannot call initialise() twice on the same service.
§Arguments
author- Author information for the initial Git commitcare_location- High-level organisational location for the commit (e.g., hospital name)
§Returns
Returns DemographicsService<Initialised> containing the newly created demographics record.
Use demographics_id() to get the UUID.
§Errors
Returns PatientError if:
- YAML serialisation of patient data fails
- Patient directory cannot be created
patient.yamlfile cannot be written- Git repository initialisation or commit fails
- Cleanup of a partially-created record directory fails (
PatientError::CleanupAfterInitialiseFailed)
§Safety & Rollback
If any operation fails during initialisation, this method attempts to clean up the
partially-created patient directory. If cleanup also fails, a
PatientError::CleanupAfterInitialiseFailed is returned with details of both errors.
Source§impl DemographicsService<Initialised>
impl DemographicsService<Initialised>
Sourcepub fn with_id(
cfg: Arc<CoreConfig>,
demographics_id: &str,
) -> PatientResult<Self>
pub fn with_id( cfg: Arc<CoreConfig>, demographics_id: &str, ) -> PatientResult<Self>
Creates a demographics service for an existing record.
Use this when you already have a demographics record and want to perform operations on it, such as updating demographics or listing patients.
§Arguments
cfg- Core configuration containing patient data directory pathsdemographics_id- UUID string of the existing demographics record
Sourcepub fn demographics_id(&self) -> &ShardableUuid
pub fn demographics_id(&self) -> &ShardableUuid
Returns the demographics UUID.
Source§impl DemographicsService<Initialised>
impl DemographicsService<Initialised>
Sourcepub fn update(
&self,
given_names: Vec<NonEmptyText>,
last_name: &str,
birth_date: &str,
) -> PatientResult<()>
pub fn update( &self, given_names: Vec<NonEmptyText>, last_name: &str, birth_date: &str, ) -> PatientResult<()>
Updates the demographics of an existing patient.
Reads the existing patient YAML file, updates the name and birth date fields, and writes the changes back to the file. This operation does not create a new Git commit—callers must commit changes separately if needed.
§Arguments
given_names- Vector of given names for the patientlast_name- Family/last name of the patientbirth_date- Birth date of the patient as a string
§Errors
Returns PatientError if:
patient.yamlfile cannot be read, deserialised, serialised, or written
Source§impl<S> DemographicsService<S>
impl<S> DemographicsService<S>
Sourcepub fn list_patients(&self) -> Vec<Patient>
pub fn list_patients(&self) -> Vec<Patient>
Lists all patient records from the file system.
Traverses the sharded directory structure under patient_data/demographics/
and reads all patient.yaml files to reconstruct patient records.
§Returns
Vector of protobuf Patient messages containing all found patient records.
Individual patient files that cannot be parsed are logged as warnings and skipped.
§Directory Structure
Expects patients stored in:
<patient_data_dir>/demographics/<s1>/<s2>/<uuid>/patient.yamlwhere s1/s2 are the first four hex characters of the UUID.
Trait Implementations§
Source§impl<S: Clone> Clone for DemographicsService<S>
impl<S: Clone> Clone for DemographicsService<S>
Source§fn clone(&self) -> DemographicsService<S>
fn clone(&self) -> DemographicsService<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<S> Freeze for DemographicsService<S>where
S: Freeze,
impl<S> RefUnwindSafe for DemographicsService<S>where
S: RefUnwindSafe,
impl<S> Send for DemographicsService<S>where
S: Send,
impl<S> Sync for DemographicsService<S>where
S: Sync,
impl<S> Unpin for DemographicsService<S>where
S: Unpin,
impl<S> UnwindSafe for DemographicsService<S>where
S: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request