nexusLIMS.db.session_handler#

Classes and methods to interact with sessions from the NexusLIMS database.

Module Contents#

Classes#

Session

A representation of a session in the NexusLIMS database.

Functions#

get_sessions_to_build

Get list of sessions that need to be built from the NexusLIMS database.

get_all_session_logs

Fetch all session logs from the database and return SessionLogs.

API#

class nexusLIMS.db.session_handler.Session(session_identifier: str, instrument: Instrument, dt_range: Tuple[datetime, datetime], user: str)[source]#

A representation of a session in the NexusLIMS database.

A record of an individual session as read from the Nexus Microscopy facility session database. Created by combining two SessionLog objects with status "TO_BE_BUILT".

Parameters:
  • session_identifier – The unique identifier for an individual session on an instrument

  • instrument – An object representing the instrument associated with this session

  • dt_range – A tuple of two datetime objects representing the start and end of this session )in that order

  • user (str) – The username associated with this session (may not be trustworthy)

update_session_status(status: RecordStatus)[source]#

Update the status of this Session in the NexusLIMS database.

Specifically, update the record_status in any session logs for this Session.

Parameters:

status (RecordStatus) – The new status for this session (type-safe enum value)

Returns:

success – Whether the update operation was successful

Return type:

bool

insert_record_generation_event() dict[source]#

Insert record generation event to session log.

Insert a log for this session into the session database with event_type "RECORD_GENERATION" and the current time (with local system timezone) as the timestamp.

Returns:

res – A dictionary containing the inserted log information

Return type:

dict

nexusLIMS.db.session_handler.get_sessions_to_build() list[Session][source]#

Get list of sessions that need to be built from the NexusLIMS database.

Query the NexusLIMS database for pairs of logs with status TO_BE_BUILT and return the information needed to build a record for that session.

Returns:

sessions – A list of Session objects containing the sessions that need their record built. Will be an empty list if there’s nothing to do.

Return type:

list[Session]

nexusLIMS.db.session_handler.get_all_session_logs() list[SessionLog][source]#

Fetch all session logs from the database and return SessionLogs.

Returns:

session_logs – A list of all SessionLog objects from the database, ordered by timestamp. Will be an empty list if there are no session logs.

Return type:

list[SessionLog]