def create_dicom_node(node: dicom.DicomNodeCreate, user: User = Depends(token_auth), db: Session = Depends(session)): """ Create a dicom node """ q = db.query(DicomNode).filter_by(title=node.title, host=node.host, port=node.port) if not (db_node := q.first()): db_node = DicomNode(**node.dict(), user_id=user.id) db_node.save(db) return db_node
def c_echo(host: str, port: int, title: str): """ Performs a DICOM c_echo to dicom node """ node = DicomNode(title=title, host=host, port=port) if not scu.send_echo(node): raise HTTPException(503, "C-Echo Failed")
def update_or_create_user_node(db, global_node: DicomNode, user_id: int) -> DicomNode: if node := DicomNode.query(db).filter_by(title=global_node.title, host=global_node.host, user_id=user_id).first(): node.last_connected = datetime.utcnow()
modality=ds.Modality, date_received=datetime.today() ) series.save(db) # Grab the save path so we can release the session connection save_path = pathlib.Path(series.get_abs_path()) / (ds.SOPInstanceUID + '.dcm') shutil.move(file_path, save_path) db.commit() shutil.rmtree(folder) def update_or_create_user_node(db, global_node: DicomNode, user_id: int) -> DicomNode: if node := DicomNode.query(db).filter_by(title=global_node.title, host=global_node.host, user_id=user_id).first(): node.last_connected = datetime.utcnow() else: node = DicomNode( title=global_node.title, host=global_node.host, user_id=user_id, first_connected=datetime.utcnow(), last_connected=datetime.utcnow(), implementation_version_name=global_node.implementation_version_name, input=True, ).save(db) return node
def get_from_connection(self, title, host, **kwargs): kwargs = {k: v for k, v in kwargs.items() if v is not None} return DicomNode.query(self._db).filter_by(title=title, host=host, **kwargs).first()
from datetime import datetime from api.models.dicom import DicomNode from api.services._base import DatabaseService class DicomNodeService(DatabaseService): def get_from_connection(self, title, host, **kwargs): kwargs = {k: v for k, v in kwargs.items() if v is not None} return DicomNode.query(self._db).filter_by(title=title, host=host, **kwargs).first() def update_or_create_from_connection(self, title, host, user_id: int = None, **kwargs) -> DicomNode: if node := self.get_from_connection(title, host, user_id=user_id): node.last_connected = datetime.utcnow() else: node = DicomNode( **kwargs, title=title, host=host, first_connected=datetime.utcnow(), last_connected=datetime.utcnow(), ).save(self._db) return node
from api import config from api.models.user import User from api.models.container import Container from api.models.dicom import DicomNode from api.queries import internal def pre_populate_internal(db): """ Adds a default internal user and default containers if they do not exist """ if not (user := internal.get_internal_user(db)): user = User(username=config.INTERNAL_USERNAME, name=config.INTERNAL_USERNAME) user.save(db) if not internal.get_default_containers(db): [ Container(user_id=user.id, is_shared=True, **kwargs).save(db) for kwargs in config.DEFAULT_CONTAINERS ] if not internal.get_return_to_sender(db): DicomNode(title='Dynamic', host='*', port=-1, output=True, user_id=user.id).save(db)
def save_node_for_user_id(user_id: int, db: Session): node = DicomNode(title='test', host='test', port='0000', user_id=user_id) node.save(db) return node