Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new env variable for setting Value set version #32

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions TerminologService/TermServerConstants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import json
import os

TERMINOLOGY_SERVER_ADDRESS = os.environ.get('ONTOLOGY_SERVER_ADDRESS')
SERVER_CERTIFICATE = os.environ.get('SERVER_CERTIFICATE')
PRIVATE_KEY = os.environ.get('PRIVATE_KEY')

# Get the current working directory
current_working_dir = os.getcwd()
print(current_working_dir)
mapping_path = os.environ.get('ONTO_MAPPING_PATH', os.path.join(current_working_dir, '..', '..', 'mapping.json'))
with open(mapping_path, 'r') as file:
MAPPING_ONTO_VERSION = json.load(file)
2 changes: 1 addition & 1 deletion TerminologService/ValueSetResolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests

from TerminologService.TermServerConstants import TERMINOLOGY_SERVER_ADDRESS, SERVER_CERTIFICATE, PRIVATE_KEY
from TerminologService.TermServerConstants import TERMINOLOGY_SERVER_ADDRESS, SERVER_CERTIFICATE, PRIVATE_KEY, MAPPING_ONTO_VERSION
from TerminologService.valueSetToRoots import create_vs_tree, expand_value_set
from model.UiDataModel import TermCode

Expand Down
22 changes: 19 additions & 3 deletions TerminologService/valueSetToRoots.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import bisect
import logging
from typing import List

import requests
import locale

from sortedcontainers import SortedSet

from TerminologService.TermServerConstants import TERMINOLOGY_SERVER_ADDRESS, SERVER_CERTIFICATE, PRIVATE_KEY
from TerminologService.TermServerConstants import TERMINOLOGY_SERVER_ADDRESS, SERVER_CERTIFICATE, PRIVATE_KEY, MAPPING_ONTO_VERSION
from model.UiDataModel import TermCode, TermEntry

locale.setlocale(locale.LC_ALL, 'de_DE')
Expand All @@ -22,7 +23,23 @@ def expand_value_set(url: str, onto_server: str = TERMINOLOGY_SERVER_ADDRESS):
if '|' in url:
url = url.replace('|', '&version=')
term_codes = SortedSet()
response = requests.get(onto_server + f"ValueSet/$expand?url={url}", cert=(SERVER_CERTIFICATE, PRIVATE_KEY))
version = MAPPING_ONTO_VERSION.get('canonical_address')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a file if you always get the same version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It ensures that the system remains adaptable and scalable as more version-specific requirements emerge.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but please a variable here and not a string in that case. Probably you want to use the actual canonical_adress not a string.

onto_server = TERMINOLOGY_SERVER_ADDRESS

if version:
canonical_address = f"ValueSet/$expand?url={url}&system-version={version}"
else:
canonical_address = f"ValueSet/$expand?url={url}"
logging.debug(f"No version found for canonical address: {canonical_address}")
Comment on lines +31 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log output is not in line with the implementation. You never look up {canonical_address} but "canonical_address"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be a better logging message which clarifys the purpose of the error?
logging.debug(f"No version was provided.Using canonical address: {canonical_address}")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


complete_url = onto_server + canonical_address
print(complete_url)
try:
response = requests.get(complete_url, cert=(SERVER_CERTIFICATE, PRIVATE_KEY))
response.raise_for_status()
except requests.exceptions.RequestException as e:
logging.error(f"An error occurred while requesting the ontology server: {e}")

print(response.status_code)
if response.status_code == 200:
value_set_data = response.json()
Expand Down Expand Up @@ -50,7 +67,6 @@ def expand_value_set(url: str, onto_server: str = TERMINOLOGY_SERVER_ADDRESS):
print(response.content)
return []
# raise Exception(response.status_code, response.content)
print(term_codes)
return term_codes


Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions mapping.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can only assume this intended to be the canonical address of the valueset that requires the snomed version?
In that case you would have a change the key accordingly and also add all snomed based valuesets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mapping.json file, which contains version information, has been updated as follows:
{ "snomed-version": "http%3A%2F%2Fsnomed.info%2Fsct%7Chttp%3A%2F%2Fsnomed.info%2Fsct%2F900000000000207008%2Fversion%2F20240101" }

Currently, only one version of SNOMED is provided in this file because this update specifically applies to ICU use cases. Additional versions will be added as they become available and relevant to other domains.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you get the key information from? It shouldn't be static.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"canonical_address": "http%3A%2F%2Fsnomed.info%2Fsct%7Chttp%3A%2F%2Fsnomed.info%2Fsct%2F900000000000207008%2Fversion%2F20240101"
}