health-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Health-dev] Integration of Orthanc (module health_orthanc)


From: p . rosik
Subject: [Health-dev] Integration of Orthanc (module health_orthanc)
Date: Wed, 17 May 2023 16:53:01 +0200
User-agent: SOGoMail 5.8.2

Hello dear GNU Health community ,

I am currently writing my master thesis and trying to implement a periodic synchronisation of the Orthanc and GNU Health DB. Unfortunately I run into some problems. I create a background thread in which the synchronisation should be done periodically. My idea was to initialise the variable "sync_thread = None" in the class "OrthancServerConfig" in order to be able to start and stop the synchronisation via a start and stop button. In addition, I use the already implemented method "sync" of the same class. I have already tried this:

class SyncThread(threading.Thread):
    """A background thread that periodically synchronizes data with an Orthanc server."""
    def __init__(self, servers=None, timeout=180):
        """
        Initialize the SyncThread object as a background service.
        :param servers: A list of Orthanc servers.
        :type servers: list
        :param timeout: The time interval (in seconds) between each synchronization.
        :type timeout: int
        """
        threading.Thread.__init__(self, name="OrthancPeriodicSyncronizationThread")
        self.daemon = True
        self.servers = servers
        self.timeout = timeout
        self.stop_event = threading.Event()


    def run(self):
        """Call loop with timeout to synchronize the Orthanc DB with the GNU Health DB."""
        with Transaction().start():         <-- (line in which error 1 occurs)
            while not self.stop_event.is_set():
                OrthancServerConfig.sync(self.servers)
                self.stop_event.wait(self.timeout)

    
    def stop(self):
        """Stop the synchronization thread."""
        self.stop_event.set()


​​​​​​Class OrthancServerConfig​(ModelSQL, ModelView):
    sync_thread = None
    ...
    @classmethod
    @ModelView.button
    def start_periodic_sync(cls, servers):

        """
        Initializes the synchronization of data with Orthanc as a background service.
        :param servers: A list of Orthanc servers.
        :type servers: list
        """
        if cls.sync_thread is not None:
            raise UserWarning("Synchronization is already running!")
        else:
            cls.sync_thread = SyncThread(servers=servers)
            cls.sync_thread.start()


    @classmethod
    @ModelView.button
    def stop_periodic_sync(cls):  <-- (error 2 occurs here, when "stop"-button is pressed)

        """
        Stop the synchronization thread.
        """
        if cls.sync_thread is None:
            raise UserWarning("No synchronization is performed!")
        else:
            cls.sync_thread.stop()
            cls.sync_thread.join()
            cls.sync_thread = None


2 errors occur, for which I unfortunately don't know an answer to fix them. Error 1 occurs, when the "start" button is pressed and the "run"-method of the class "SyncThread" is triggered:
    orthanc/health_orthanc.py", line 66, in run
    with Transaction().start():         

    TypeError: Transaction.start() missing 2 required positional arguments: 'database_name' and 'user'
I'm not sure, if "with Transaction.start():" is necessary here, but i tried this, because i got this error before:
    orthanc/health_orthanc.py", line 269, in sync
    pool = Pool()
      File "/opt/gnuhealth/venv/lib/python3.10/site-packages/trytond/pool.py", line 61, in __new__
    database_name = Transaction().database.name
    AttributeError: 'NoneType' object has no attribute 'name'

If "with Transaction.start():" is required, unfortunately I wasn't able to figure out which are the two required arguments or if the solution is generally in a completely different direction.

The second error occurs, when the "stop" button is pressed:
    TypeError: OrthancServerConfig.stop_periodic_sync() takes 1 positional argument but 2 were given
Here I was also not able to interpret the error, because both my button and the stop method are not passed 2 arguments.

I would be grateful for any help and am available for queries!

Best regards,
​​​​​​​Patryk
 
reply via email to

[Prev in Thread] Current Thread [Next in Thread]