-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #589 from jbernal0019/master
Implement PACS list API endpoint based on a new PFDCM microservice
- Loading branch information
Showing
25 changed files
with
1,305 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ackend/core/tests/test_file_serializer.py → chris_backend/core/tests/test_serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.5 on 2024-10-22 18:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pacsfiles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='pacs', | ||
name='active', | ||
field=models.BooleanField(blank=True, default=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
import logging | ||
import time | ||
|
||
from django.conf import settings | ||
|
||
from requests import get, post, exceptions | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PfdcmClient(object): | ||
""" | ||
A pfcdm API client. | ||
""" | ||
|
||
def __init__(self): | ||
self._pfdcm_address = settings.PFDCM_ADDRESS.rstrip('/') | ||
self.content_type = 'application/json' | ||
|
||
# urls of the high level API resources | ||
self.pacs_list_url = self._pfdcm_address + '/api/v1/PACSservice/list/' | ||
self.pacs_query_url = self._pfdcm_address + '/api/v1/PACS/sync/pypx/' | ||
self.pacs_retrieve_url = self._pfdcm_address + '/api/v1/PACS/thread/pypx/' | ||
|
||
def get_pacs_list(self, timeout=30): | ||
""" | ||
Get a list of PACS names. | ||
""" | ||
headers = {'Content-Type': self.content_type, 'Accept': self.content_type} | ||
|
||
for i in range(5): | ||
try: | ||
resp = get(self.pacs_list_url, timeout=timeout, headers=headers) | ||
except (exceptions.Timeout, exceptions.RequestException) as e: | ||
logger.error(f'Error while retrieving data from pfdcm url ' | ||
f'-->{self.pacs_list_url}<--, detail: {str(e)}') | ||
if i == 4: | ||
raise | ||
time.sleep(0.4) | ||
else: | ||
return resp.json() | ||
|
||
def query(self, pacs_name, query, timeout=30): | ||
""" | ||
Send a PACS query dictionary to pfdcm. | ||
""" | ||
headers = {'Content-Type': self.content_type, 'Accept': self.content_type} | ||
data = { | ||
'PACSservice' : {'value': pacs_name}, | ||
'listenerService' : {'value': 'default'}, | ||
'PACSdirective' : query | ||
} | ||
for i in range(5): | ||
try: | ||
resp = post(self.pacs_query_url, json=data, timeout=timeout, | ||
headers=headers) | ||
except (exceptions.Timeout, exceptions.RequestException) as e: | ||
logger.error(f'Error while querying pfdcm url ' | ||
f'-->{self.pacs_query_url}<--, detail: {str(e)}') | ||
if i == 4: | ||
raise | ||
time.sleep(0.4) | ||
else: | ||
return resp.json() | ||
|
||
def retrieve(self, pacs_name, query, timeout=30): | ||
""" | ||
Send a PACS query dictionary to pfdcm to initiate a PACS retrieve. | ||
""" | ||
headers = {'Content-Type': self.content_type, 'Accept': self.content_type} | ||
data = { | ||
'PACSservice' : {'value': pacs_name}, | ||
'listenerService' : {'value': 'default'}, | ||
'PACSdirective' : query, | ||
'withFeedBack': True, | ||
'then': 'retrieve' | ||
} | ||
for i in range(5): | ||
try: | ||
resp = post(self.pacs_retrieve_url, json=data, timeout=timeout, | ||
headers=headers) | ||
except (exceptions.Timeout, exceptions.RequestException) as e: | ||
logger.error(f'Error while querying pfdcm url ' | ||
f'-->{self.pacs_retrieve_url}<--, detail: {str(e)}') | ||
if i == 4: | ||
raise | ||
time.sleep(0.4) | ||
else: | ||
return resp.json() |
Oops, something went wrong.