Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1235 ConcetpMap operations fix parameters l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
rkorytkowski committed Mar 7, 2023
1 parent ec367f9 commit bb5acac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions core/concept_maps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_public_translate_negative(self):

response = self.client.get(
f'/users/{self.user.mnemonic}/ConceptMap/$translate?'
f'system={self.org_source_B_v1.canonical_url}&code=concept_B_1')
f'system={self.org_source_B_v1.canonical_url}&code=concept_1')

self.assertEqual(response.status_code, 200)
self.assertDictEqual(response.data, {
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_translate_with_target(self):

response = self.client.get(
f'/users/{self.user.mnemonic}/ConceptMap/$translate?'
f'system={self.org_source_B_v1.canonical_url}&code=concept_B_1&target={self.org_source.canonical_url}',
f'system={self.org_source_B_v1.canonical_url}&code=concept_B_1&targetsystem={self.org_source.canonical_url}',
HTTP_AUTHORIZATION='Token ' + self.user_token)

self.assertEqual(response.status_code, 200)
Expand All @@ -490,7 +490,7 @@ def test_translate_with_target_negative(self):

response = self.client.get(
f'/users/{self.user.mnemonic}/ConceptMap/$translate?'
f'system={self.org_source_B_v1.canonical_url}&code=concept_B_1&target={self.org_source_B_v1.canonical_url}',
f'system={self.org_source_B_v1.canonical_url}&code=concept_B_1&targetsystem={self.org_source_B_v1.canonical_url}',
HTTP_AUTHORIZATION='Token ' + self.user_token)

self.assertEqual(response.status_code, 200)
Expand Down
24 changes: 15 additions & 9 deletions core/concept_maps/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.core.exceptions import ValidationError
from django.db.models import Q
from pydash import get

from core.bundles.serializers import FHIRBundleSerializer
Expand Down Expand Up @@ -95,14 +96,17 @@ def apply_filters(self, queryset):
case 'code':
queryset = queryset.filter(from_concept_code=param['valueCode'])
case 'system':
queryset = queryset.filter(from_source_url=IdentifierSerializer.convert_fhir_url_to_ocl_uri(
param['valueUri'], 'sources'))
case 'source':
queryset = queryset.filter(parent__canonical_url=param['valueUri'])
case 'target':
queryset = queryset.filter(to_source_url=IdentifierSerializer.convert_fhir_url_to_ocl_uri(
param['valueUri'], 'sources'
))
system_url = IdentifierSerializer.convert_fhir_url_to_ocl_uri(param['valueUri'], 'sources')
queryset = queryset.filter(Q(from_source__canonical_url=param['valueUri']) |
Q(from_source_url=system_url) |
Q(from_source__uri=system_url))
#TODO: implement case 'source':
#TODO: implement case 'target':
case 'targetsystem':
target_url = IdentifierSerializer.convert_fhir_url_to_ocl_uri(param['valueUri'], 'sources')
queryset = queryset.filter(Q(to_source__canonical_url=param['valueUri']) |
Q(to_source_url=target_url) |
Q(to_source__uri=target_url))
return queryset

def get_serializer(self, *args, **kwargs):
Expand All @@ -118,8 +122,10 @@ def get_serializer(self, *args, **kwargs):

if mapping.to_source and mapping.to_source.canonical_url:
to_url = mapping.to_source.canonical_url
else:
elif mapping.to_source_url:
to_url = IdentifierSerializer.convert_ocl_uri_to_fhir_url(mapping.to_source_url, RESOURCE_TYPE)
elif mapping.to_source:
to_url = IdentifierSerializer.convert_ocl_uri_to_fhir_url(mapping.to_source.uri, RESOURCE_TYPE)

matches.append({
'name': 'match',
Expand Down

0 comments on commit bb5acac

Please sign in to comment.