Struct DemographicsService

Source
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>

Source

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>

Source

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 commit
  • care_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.yaml file 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>

Source

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 paths
  • demographics_id - UUID string of the existing demographics record
Source

pub fn demographics_id(&self) -> &ShardableUuid

Returns the demographics UUID.

Source§

impl DemographicsService<Initialised>

Source

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 patient
  • last_name - Family/last name of the patient
  • birth_date - Birth date of the patient as a string
§Errors

Returns PatientError if:

  • patient.yaml file cannot be read, deserialised, serialised, or written
Source§

impl<S> DemographicsService<S>

Source

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.yaml

where s1/s2 are the first four hex characters of the UUID.

Trait Implementations§

Source§

impl<S: Clone> Clone for DemographicsService<S>

Source§

fn clone(&self) -> DemographicsService<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for DemographicsService<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more