Struct ClinicalService

Source
pub struct ClinicalService<S> { /* private fields */ }
Expand description

Service for managing clinical record operations.

This service uses the type-state pattern to enforce correct usage at compile time. The generic parameter S can be either Uninitialised or Initialised, determining which operations are available.

§Type States

Implementations§

Source§

impl ClinicalService<Uninitialised>

Source

pub fn new(cfg: Arc<CoreConfig>) -> Self

Creates a new ClinicalService in the uninitialised state.

This is the starting point for creating a new clinical record. The returned service can only call initialise() to create the record.

§Arguments
  • cfg - The core configuration containing paths, templates, and system settings.
§Returns

A ClinicalService<Uninitialised> ready to initialise a new clinical record.

Source§

impl ClinicalService<Initialised>

Source

pub fn with_id(cfg: Arc<CoreConfig>, clinical_id: Uuid) -> Self

Creates a ClinicalService in the initialised state with an existing clinical ID.

Use this when you already have a clinical record and want to perform operations on it, such as linking to demographics or updating the EHR status.

§Arguments
  • cfg - The core configuration containing paths, templates, and system settings.
  • clinical_id - The UUID of an existing clinical record.
§Returns

A ClinicalService<Initialised> ready to operate on the specified clinical record.

§Note

This constructor does not validate that the clinical record actually exists. Operations on a non-existent record will fail at runtime.

Source

pub fn clinical_id(&self) -> Uuid

Returns the clinical ID for this initialised service.

§Returns

The UUID of the clinical record associated with this service.

Source§

impl ClinicalService<Uninitialised>

Source

pub fn initialise( self, author: Author, care_location: NonEmptyText, ) -> PatientResult<ClinicalService<Initialised>>

Initialises a new clinical record for a patient.

This function creates a new clinical entry with a unique UUID, stores it in a sharded directory structure, copies the clinical template into the patient’s directory, writes an initial ehr_status.yaml, and initialises a Git repository for version control.

This method consumes self and returns a new ClinicalService<Initialised> on success, enforcing at compile time that you cannot call initialise() twice on the same service.

§Arguments
  • author - The author information for the initial Git commit. Must have a non-empty name.
  • care_location - High-level organisational location for the commit (e.g. hospital name). Must be a non-empty string.
§Returns

Returns ClinicalService<Initialised> containing the newly created clinical record. Use clinical_id() to get the UUID.

§Errors

Returns a PatientError if:

Source§

impl ClinicalService<Initialised>

Links the clinical record to the patient’s demographics.

This function updates the clinical record’s ehr_status.yaml file to include an external reference to the patient’s demographics record.

The clinical UUID is obtained from the service’s internal state (via clinical_id()), ensuring type safety and preventing mismatched UUIDs.

§Arguments
  • author - The author information for the Git commit recording this change. Must have a non-empty name.
  • care_location - High-level organisational location for the commit (e.g. hospital name). Must be a non-empty string.
  • demographics_uuid - The UUID of the associated patient demographics record. Must be a canonical 32-character lowercase hex string.
  • namespace - Optional namespace for the external reference URI. If None, uses the value configured in CoreConfig. The namespace must be URI-safe (no special characters like <, >, /, \).
§Returns

Returns Ok(()) on success. The ehr_status.yaml file is updated and committed to Git.

§Errors

Returns a PatientError if:

§Safety & Rollback

If the file write or Git commit fails, this method attempts to restore the previous content of ehr_status.yaml.

Source

pub fn create_letter( &self, author: &Author, care_location: NonEmptyText, body_content: Option<NonEmptyText>, attachment_files: &[PathBuf], clinical_lists: Option<&[ClinicalList]>, ) -> PatientResult<TimestampId>

Creates a new clinical letter with optional body and/or attachments.

This is the unified function for creating letters with any combination of:

  • Body content only (markdown text saved as body.md)
  • Attachments only (files stored via FilesService)
  • Both body content AND attachments

At least one of body_content or attachment_files must be provided.

§Arguments
  • author - The author information for the Git commit. Must have a non-empty name.
  • care_location - High-level organisational location for the commit (e.g. hospital name). Must be a non-empty string.
  • body_content - Optional Markdown content for the letter body (body.md).
  • attachment_files - Paths to files to attach (e.g., PDFs, images). Can be empty.
  • clinical_lists - Optional clinical lists to include in the composition.
§Returns

Returns the generated timestamp ID for the letter on success.

§Errors

Returns a PatientError if:

  • Both body_content and attachment_files are empty/None
  • The author’s name is empty or whitespace-only
  • The care location is empty or whitespace-only
  • The clinical UUID cannot be parsed
  • Any attachment file cannot be read or stored
  • Creating the composition.yaml content fails
  • Writing files or committing to Git fails
Source

pub fn new_letter( &self, author: &Author, care_location: NonEmptyText, letter_content: NonEmptyText, clinical_lists: Option<&[ClinicalList]>, ) -> PatientResult<TimestampId>

Creates a new clinical letter with body content.

This is a convenience wrapper around create_letter for the common case of creating a letter with only body content.

§Arguments
  • author - The author information for the Git commit.
  • care_location - High-level organisational location for the commit.
  • letter_content - The Markdown content for the letter body.
  • clinical_lists - Optional clinical lists to include.
§Returns

Returns the generated timestamp ID for the letter on success.

This function creates a new letter with the specified content, generates a unique timestamp-based ID, and commits both the composition.yaml and body.md files to Git.

§Arguments
  • author - The author information for the Git commit. Must have a non-empty name.
  • care_location - High-level organisational location for the commit (e.g. hospital name). Must be a non-empty string.
  • letter_content - The Markdown content for the letter body (body.md).
§Returns

Returns the generated timestamp ID for the letter on success.

§Errors

Returns a PatientError if:

  • The author’s name is empty or whitespace-only
  • The care location is empty or whitespace-only
  • The clinical UUID cannot be parsed
  • Creating the composition.yaml content fails
  • Writing files or committing to Git fails
Source

pub fn read_letter(&self, timestamp_id: &str) -> PatientResult<ReadLetterResult>

Reads an existing clinical letter.

This function reads both the body.md and composition.yaml files for a letter, parses the composition metadata, and returns them together.

§Arguments
  • timestamp_id - The timestamp ID of the letter to read.
§Returns

Returns a ReadLetterResult containing both the body content and parsed letter data.

§Errors

Returns a PatientError if:

  • The timestamp ID cannot be parsed
  • The clinical UUID cannot be parsed
  • The body.md or composition.yaml file does not exist
  • Reading either file fails
  • Parsing the composition.yaml fails
Source

pub fn get_letter_attachments( &self, timestamp_id: &str, ) -> PatientResult<Vec<LetterAttachment>>

Retrieves all attachments for a clinical letter.

This function reads all attachment metadata files from the letter’s attachments directory and retrieves the actual file content from storage.

§Arguments
  • timestamp_id - The timestamp ID of the letter.
§Returns

Returns a vector of LetterAttachment containing metadata and file content for each attachment.

§Errors

Returns a PatientError if:

  • The timestamp ID cannot be parsed
  • The clinical UUID cannot be parsed
  • The attachments directory does not exist or cannot be read
  • Any attachment metadata file cannot be read or parsed
  • Any file cannot be retrieved from storage
Source

pub fn new_letter_with_attachments( &self, author: &Author, care_location: NonEmptyText, attachment_files: &[PathBuf], clinical_lists: Option<&[ClinicalList]>, ) -> PatientResult<TimestampId>

Creates a new clinical letter with file attachments.

This is a convenience wrapper around create_letter for creating a letter with only attachments (no body content).

§Arguments
  • author - The author information for the Git commit.
  • care_location - High-level organisational location for the commit.
  • attachment_files - Paths to files to attach (e.g., PDFs, images).
  • clinical_lists - Optional clinical lists to include.
§Returns

Returns the generated timestamp ID for the letter on success.

Trait Implementations§

Source§

impl<S: Clone> Clone for ClinicalService<S>

Source§

fn clone(&self) -> ClinicalService<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 ClinicalService<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 ClinicalService<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for ClinicalService<S>
where S: RefUnwindSafe,

§

impl<S> Send for ClinicalService<S>
where S: Send,

§

impl<S> Sync for ClinicalService<S>
where S: Sync,

§

impl<S> Unpin for ClinicalService<S>
where S: Unpin,

§

impl<S> UnwindSafe for ClinicalService<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