Changing program settings while saving personal settings

prehistory

One medical organization implemented solutions based on Orthanc PACS servers and Radiant DICOM client. During the setup, we found out that each DICOM client must be described in PACS servers as follows:

  • Client name
  • AE name (must be unique)
  • A TCP port that is automatically opened on the client side and receives DICOM exams from the PACS server (i.e. the server sort of pushes them towards the client - initiating the connection first)
  • IP Address

After setting up Radiant, clients received the following information for reflection - for each client, setting up the software with the above parameters led to the filling of the file pacs.xml, which was located in the user profile (path: %APPDATA%RadiantViewerpacs.xml). At the same time, the config of one client differed from another by at least two parameters (the AE-name is different for everyone, and the port is basically the same, except for terminal clients running on the same server - there the ports also had to be assigned different).

pacs.xml file example link:

For about half a year everything was fine, the system started working ... and then we got to "underwater stones":

  • We need to put into operation several new PACS servers that will replace the old ones (where disk space began to run out). PACS servers in virtual machines, but this is not about that;
  • We need to somehow centrally change the unique configurations (with two different parameters) on 200 machines (their number has been regularly increasing);
  • Taking into account the growth rates of survey volumes, the decision is not needed one-time, but replicated and regular (for example, once every 1-3 months).

Solution below.

The choice of tools for solving the problem

Initially, there were attempts to find some solution that changed the pacs.xml file on the client side and made changes to the list of PACS servers without touching the AE name and TCP port settings. Windows clients at that time were based on both Windows XP and Windows 7 - so there were attempts to write something like that based on VBScript. But alas, it was not possible to master such a task, due to the complete lack of experience in writing something complex and complex in this language. Attempts to find and rewrite were also unsuccessful (here it should be noted that there was already a different plan in my head, so I didn’t hammer with VBScript for more than 3-4 hours).

In the end, I settled on the following solution:

  • Collect by group policy all pacs.xml files in one place on any server in a network resource;
  • Change files en masse (there was already experience in solving such problems - using Perl);
  • Also, use group policies to update client settings.

Collecting Files Using Group Policy

The simplest part is that when a client logs into his profile, he executes a certain .bat file with his rights, which says:

echo off
If exist %APPDATA%RadiantViewerpacs.xml copy %APPDATA%RadiantViewerpacs.xml srv.test.localpconfigs$pacs-%COMPUTERNAME%-%USERNAME%.xml

Thus, pacs.xml files will be accumulated on the server in a hidden resource, the name of which contains information from which computer and from which user this config was copied.

The most difficult thing was to wait until this policy worked out for all users.

Changing Configurations with a Perl Script

We will need Active Perl for Windows from ActiveState, as well as the XML::Writer module, which can be installed using the command ppm install XML-Writer.

The script itself turned out to be quite simple:

use XML::Writer;
 
# ΠžΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ ΠΏΠ°ΠΏΠΊΡƒ с ΠΎΡ‚Ρ‡Π΅Ρ‚Π°ΠΌΠΈ, ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅ΠΌ ссписок (удаляСм лишнСС):
	$report_dir = "C:Perl64WORKPACS-xml3";
	opendir(DIR, "$report_dir") or die "НС ΠΌΠΎΠ³Ρƒ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ с ΠΎΡ‚Ρ‡Π΅Ρ‚Π°ΠΌΠΈ!";
	@report_files = readdir DIR;
	shift (@report_files); # удаляСм Ρ‚ΠΎΡ‡ΠΊΡƒ ΠΈΠ· элСмСнтов массива (.)
	shift (@report_files); # удаляСм Π΄Π²Π΅ Ρ‚ΠΎΡ‡ΠΊΠΈ ΠΈΠ· элСмСнтов массива (..)
#	print "@report_files";
	closedir(DIR);
 
# НачинаСм ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ»Ρ‹ - ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΌΡƒ Π·Π° Ρ€Π°Π·. НуТно ΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ AET ΠΈ Π½ΠΎΠΌΠ΅Ρ€ ΠΏΠΎΡ€Ρ‚Π° Π² ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅.
foreach $analiz_file (@report_files) 
{
	$full_path_to_file="C:Perl64WORKPACS-xml3".$analiz_file;
	open (INFO, $full_path_to_file);
 
	while ($line = <INFO>)
	{
		# ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ $aet ΠΈ $port содСрТат ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ XML Ρ„Π°ΠΉΠ»Π°:
		my ($other1, $aet, $other2, $port, $other3) = split /"/, $line, 5;
		# Если встрСчаСтся строка listener - Ρ‚ΠΎ ΠΌΡ‹ дошли Π΄ΠΎ Π½ΡƒΠΆΠ½ΠΎΠΉ строчки ΠΈ ΠΌΠΎΠΆΠ½ΠΎ Ρ„ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π½ΠΎΠ²Ρ‹ΠΉ XML:
		if ($other1 =~ 'listener')
			{
				# Π€ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ Π½ΠΎΠ²Ρ‹ΠΉ XML c Π½ΡƒΠΆΠ½Ρ‹ΠΌΠΈ полями ΠΈ Π΄Π°Π½Π½Ρ‹ΠΌΠΈ:
				my $writer = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, );
				$writer->xmlDecl('utf-8');
				$writer->startTag('pacs');
				$writer->startTag('listener', ae => $aet, port => $port);
				$writer->endTag();
				$writer->startTag('hosts');
				$writer->startTag('host', name => 'MRT', ae => 'ORTHANC', ip => 'XX.YY.214.17', ts => '1.2.840.10008.1.2.1', port => '4242', maxassoc => '1', allpres => '0', search => '1', protocol => '1', searchcharset => '', wildcards => '3', carets => '0');
				$writer->endTag();
				$writer->startTag('host', name => 'KT', ae => 'ORTHANC2', ip => 'XX.YY.215.253', ts => '1.2.840.10008.1.2.1', port => '4242', maxassoc => '1', allpres => '0', search => '1', protocol => '1', searchcharset => '', wildcards => '3', carets => '0');
				$writer->endTag();
				$writer->startTag('host', name => 'R', ae => 'ORTHANC3', ip => 'XX.YY.215.252', ts => '1.2.840.10008.1.2.1', port => '4242', maxassoc => '1', allpres => '0', search => '1', protocol => '1', searchcharset => '', wildcards => '3', carets => '0');
				$writer->endTag();
				$writer->startTag('host', name => 'KT-20180501-20180831', ae => 'ORTHANC4', ip => 'XX.YY.215.251', ts => '1.2.840.10008.1.2.1', port => '4242', maxassoc => '1', allpres => '0', search => '1', protocol => '1', searchcharset => '', wildcards => '3', carets => '0');
				$writer->endTag();
				$writer->startTag('host', name => 'KT-20180901-20181130', ae => 'ORTHANC5', ip => 'XX.YY.215.250', ts => '1.2.840.10008.1.2.1', port => '4242', maxassoc => '1', allpres => '0', search => '1', protocol => '1', searchcharset => '', wildcards => '3', carets => '0');
				$writer->endTag();
				$writer->endTag('hosts');
				$writer->startTag('presets');
				$writer->endTag();
				$writer->startTag('lastsearch', dt => '4', mfid => '1048592');
				$writer->endTag();
				$writer->endTag('pacs');
 
				# ΠŸΠΎΠΌΠ΅Ρ‰Π°Π΅ΠΌ Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ XML Π² ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ:
				my $xml = $writer->end();
				# ΠŸΠΎΠ΄Π³ΠΎΡ‚Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ Ρ„Π°ΠΉΠ» для пСрСзаписи:
				$rewritexml = $full_path_to_file;
				# ΠŸΠ΅Ρ€Π΅ΠΏΠΈΡΡ‹Π²Π°Π΅ΠΌ XML Ρ„Π°ΠΉΠ»Ρ‹ Π½ΠΎΠ²Ρ‹ΠΌΠΈ Π΄Π°Π½Π½Ρ‹ΠΌΠΈ:
				open (NEWXML, ">$rewritexml");
				print NEWXML $xml;
				close (NEWXML);				
			}
	}
 
}

The principle of its work:

  • Open the directory where we have collected pacs.xml configurations from clients and put the list of files in a scalar array (@report_files);
  • In the loop, we process one file at a time and read it line by line;
  • Split each line into 5 parts using quotes as a delimiter;
  • We find the line with the word listener and put data unique for each file (AE-client name and TCP port number) into two variables;
  • After that, we simply form a new XML file, enter unique parameters into it, and then insert the required number of PACS servers with their parameters - those. that for which everything was started)
  • We overwrite the new XML file on top of the old one.

It should be noted that in fact I use this script not completely automatically - in fact, I copy the collected configs to a separate directory and then, by running the script, I change them all together. Further selective check - and configs can be poured back on machines.

Distributing modified pacs.xml files to clients

The simplest thing that came to my mind was to make changes to the already working .bat file that collects configurations from clients and add the line:

If exist %APPDATA%RadiantViewerpacs.xml copy /Y srv.test.localpconfigsnew$pacs-%COMPUTERNAME%-%USERNAME%.xml %APPDATA%RadiantViewerpacs.xml

The final .bat file looks like this:

@echo off
If exist %APPDATA%RadiantViewerpacs.xml copy %APPDATA%RadiantViewerpacs.xml srv.test.localpconfigs$pacs-%COMPUTERNAME%-%USERNAME%.xml
If exist %APPDATA%RadiantViewerpacs.xml copy /Y srv.test.localpconfigsnew$pacs-%COMPUTERNAME%-%USERNAME%.xml %APPDATA%RadiantViewerpacs.xml

Conclusion

Such is "knee" solution. We have already tested it twice (in September 2018 and in February 2019), while the flight is normal. Of course, it does not update 100% of clients, but close to this value - we finish the rest remotely. Script by link.

Source: habr.com

Add a comment