From affc52530f7b77abfabeecc0437570bddea419d1 Mon Sep 17 00:00:00 2001 From: Aleksander Eskilson Date: Thu, 29 Nov 2018 16:59:09 -0600 Subject: [PATCH] issue-38: adding new_version parameter and tests (#39) --- .gitignore | 3 +++ python/bunsen/codes/__init__.py | 5 ++++- python/pom.xml | 2 +- python/tests/test_bunsen_r4.py | 26 ++++++++++++++++++++++++++ python/tests/test_bunsen_stu3.py | 26 ++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5fc18e9b..647800c9 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ docs/build # Test Artifacts # *.crc + +# VirtualEnv # +venv diff --git a/python/bunsen/codes/__init__.py b/python/bunsen/codes/__init__.py index 3c95cb08..b5fe4b88 100644 --- a/python/bunsen/codes/__init__.py +++ b/python/bunsen/codes/__init__.py @@ -392,7 +392,7 @@ def with_disjoint_value_sets_from_directory(self, path, database="ontologies"): self._jfunctions, self._java_package) - def add_values(self, url, version, values): + def add_values(self, url, version, new_version, values): """ Returns a new ValueSets instance with the given values added to an existing value set. The values parameter must be a list of the form @@ -400,10 +400,13 @@ def add_values(self, url, version, values): :param url: URL of the ValueSet to add values to :param version: Version of the ValueSet to add values to + :param new_version: Version of the updated ValueSet to which new values + have been added :param mappings: A list of tuples representing the values to add :return: a :class:`ValueSets` instance with the added values """ value_set = self._jvalue_sets.getValueSet(url, version) + value_set.setVersion(new_version) _add_values_to_value_set(self._jvm, value_set, values) diff --git a/python/pom.xml b/python/pom.xml index 53148fa9..801159a2 100644 --- a/python/pom.xml +++ b/python/pom.xml @@ -41,7 +41,7 @@ ${skip.python.tests} - ${project.basedir} + ${env.PYTHONPATH}:${project.basedir} ${project.parent.basedir}/bunsen-shaded/target/bunsen-shaded-${project.version}.jar diff --git a/python/tests/test_bunsen_r4.py b/python/tests/test_bunsen_r4.py index 7e013b27..1bc33dee 100644 --- a/python/tests/test_bunsen_r4.py +++ b/python/tests/test_bunsen_r4.py @@ -211,6 +211,32 @@ def test_add_valueset(spark_session): assert appended.get_value_sets().count() == 1 assert appended.get_values().count() == 3 +def test_add_values(spark_session): + + value_sets = create_value_sets(spark_session) + + original = [('http://snomed.info/sct', '75367002')] + + added = [('http://snomed.info/sct', '271649006')] + + appended = value_sets.with_new_value_set(url='urn:cerner:test:valuesets:testvalueset', + version='0.1', + values=original) \ + .add_values(url='urn:cerner:test:valuesets:testvalueset', + version='0.1', + new_version='0.2', + values=added) + + assert appended.get_values().count() == 3 + assert appended.get_values() \ + .where(col('valueseturi') == 'urn:cerner:test:valuesets:testvalueset') \ + .where(col('valuesetversion') == '0.1') \ + .count() == 1 + assert appended.get_values() \ + .where(col('valueseturi') == 'urn:cerner:test:valuesets:testvalueset') \ + .where(col('valuesetversion') == '0.2') \ + .count() == 2 + def test_latest_valueset_version(spark_session): value_sets = create_value_sets(spark_session) diff --git a/python/tests/test_bunsen_stu3.py b/python/tests/test_bunsen_stu3.py index 30de4f46..31a99570 100644 --- a/python/tests/test_bunsen_stu3.py +++ b/python/tests/test_bunsen_stu3.py @@ -211,6 +211,32 @@ def test_add_valueset(spark_session): assert appended.get_value_sets().count() == 1 assert appended.get_values().count() == 3 +def test_add_values(spark_session): + + value_sets = create_value_sets(spark_session) + + original = [('http://snomed.info/sct', '75367002')] + + added = [('http://snomed.info/sct', '271649006')] + + appended = value_sets.with_new_value_set(url='urn:cerner:test:valuesets:testvalueset', + version='0.1', + values=original) \ + .add_values(url='urn:cerner:test:valuesets:testvalueset', + version='0.1', + new_version='0.2', + values=added) + + assert appended.get_values().count() == 3 + assert appended.get_values() \ + .where(col('valueseturi') == 'urn:cerner:test:valuesets:testvalueset') \ + .where(col('valuesetversion') == '0.1') \ + .count() == 1 + assert appended.get_values() \ + .where(col('valueseturi') == 'urn:cerner:test:valuesets:testvalueset') \ + .where(col('valuesetversion') == '0.2') \ + .count() == 2 + def test_latest_valueset_version(spark_session): value_sets = create_value_sets(spark_session)