mrqart

Broadcast filesystem updates (via inotify) over websockets. Serve javascript over HTTP for receiving websocket messages in a browser.

Module Attributes

WS_PORT

Websocket port used to send updates to browser

HTTP_PORT

HTTP port used to serve static/index.html

WS_CONNECTIONS

list of all web socket connections to broadcast to TODO: will eventually need to track station id when serving multiple scanners

STATE

track the current state of each scanner based on filename we can skip parsing a dicoms (and spamming the browser) if we've already seen the session

Functions

http_run()

Actually run web server, listening on HTTP_PORT.

main(path)

Run all services on different threads.

monitor_dirs(watcher, dcm_checker)

Perpetually wait for new dicom files.

session_from_fname(dcm_fname)

We can use the file name to see if session name has changed. Don't need to read the dicom header -- if we know the station name. Can extract from 001_sequencenum_seriesnum::.

track_ws(websocket)

Track connecting and disconnecting websocket connections.

Classes

CurSeqStation(station)

Current Sequence settings at a MR Scanner station

HttpIndex(application, request, **kwargs)

Handle index page request

WebServer()

HTTP server (tornado request handler) Currently (20241102), this is just a fancy way to serve a static page.

class mrqart.CurSeqStation(station)[source]

Current Sequence settings at a MR Scanner station

Parameters:

station (str)

update_isnew(series, seqname)[source]

Maintain count of repeats seen :return: True if is new

Parameters:

seqname (str)

Return type:

bool

mrqart.HTTP_PORT = 8080[source]

HTTP port used to serve static/index.html

class mrqart.HttpIndex(application, request, **kwargs)[source]

Handle index page request

Parameters:
  • application (Application)

  • request (HTTPServerRequest)

  • kwargs (Any)

async get()[source]

Default is just the index page

mrqart.STATE: dict[str, CurSeqStation] = {}[source]

track the current state of each scanner based on filename we can skip parsing a dicoms (and spamming the browser) if we’ve already seen the session

mrqart.WS_CONNECTIONS = {}[source]

list of all web socket connections to broadcast to TODO: will eventually need to track station id when serving multiple scanners

mrqart.WS_PORT = 5000[source]

Websocket port used to send updates to browser

class mrqart.WebServer[source]

HTTP server (tornado request handler) Currently (20241102), this is just a fancy way to serve a static page. Eventually

  • will match /scanner-id URL to station id dicom header for scanner specific page

  • could give more insite into or modify DB.

mrqart.http_run()[source]

Actually run web server, listening on HTTP_PORT. WebServer defines what is actually served (and dispatches to HttpIndex)

async mrqart.main(path)[source]

Run all services on different threads. HTTP and inotify are forked. Websocket holds the main thread.

async mrqart.monitor_dirs(watcher, dcm_checker)[source]

Perpetually wait for new dicom files. Broadcast new files to the browser over websockets.

mrqart.session_from_fname(dcm_fname)[source]

We can use the file name to see if session name has changed. Don’t need to read the dicom header – if we know the station name. Can extract from 001_sequencenum_seriesnum:

ls /data/dicomstream/20241016.MRQART_test.24.10.16_16_50_16_DST_1.3.12.2.1107.5.2.43.67078/|head
001_000001_000001.dcm
...
001_000017_000066.dcm
Parameters:

dcm_fname (PathLike)

Return type:

str

async mrqart.track_ws(websocket)[source]

Track connecting and disconnecting websocket connections.

Stored in WS_CONNECTIONS. Might eventually need a dict to broadcast only to dicom specified station id.