health-dev
[Top][All Lists]
Advanced

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

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


From: p . rosik
Subject: Re: [Health-dev] Integration of Orthanc (module health_orthanc)
Date: Fri, 19 May 2023 11:37:58 +0200
User-agent: SOGoMail 5.8.2

Hello Mathias,

there were 2 reasons why I decided to use low-level programming. In the module "health_orthanc" a button for the one-time manual synchronisation is already provided and therefore I thought it would be useful to have the synchronisation in one place to increase the usability. The other reason is that I saw in the wiki (https://en.wikibooks.org/wiki/GNU_Health/Imaging) that there should already be a tryton cronjob by activating the module. But since this is not the case, I thought that maybe there were problems with the execution of the cronjob. If you think that the solution with the use of the cronjob should actually be feasible, I would be grateful for feedback.

Best regards
Patryk



* p.rosik@stud.uni-hannover.de: " [Health-dev] Integration of Orthanc (module
health_orthanc)" (Wed, 17 May 2023 16:53:01 +0200):

Hello Patryk,

is there any special reason to do this via low level programming?

Usually regular returning tasks are performed with the included scheduler
(cron). It also offers to run the task manually once. You can have a look at
the Tryton core modules 'stock' or 'account_payment_stripe' to find examples.

Best
Mathias


> 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
>  



--

Mathias Behrle
MBSolutions
Gilgenmatten 10 A
D-79114 Freiburg

Tel: +49(761)471023
Fax: +49(761)4770816
http://www.m9s.biz
UStIdNr: DE 142009020
PGP/GnuPG key availabable from any keyserver, ID: 0xD6D09BE48405BBF6
AC29 7E5C 46B9 D0B6 1C71 7681 D6D0 9BE4 8405 BBF6

 
reply via email to

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