Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1867 | mapping checksum to expand concept u…
Browse files Browse the repository at this point in the history
…rl into source url and concept code
  • Loading branch information
snyaggarwal committed Aug 20, 2024
1 parent 942da84 commit dbf174c
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions ocldev/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,52 @@ def get_concept_fields(self, data):
}

def get_mapping_fields(self, data):
to_concept_code = getvalue(data, 'to_concept_code', None)
to_concept_url = getvalue(data, 'to_concept_url', None)
to_source_url = getvalue(data, 'to_source_url', None)
to_source_version = getvalue(data, 'to_source_version', None)
from_concept_code = getvalue(data, 'from_concept_code', None)
from_concept_url = getvalue(data, 'from_concept_url', None)
from_source_url = getvalue(data, 'from_source_url', None)
from_source_version = getvalue(data, 'from_source_version', None)

def expand_concept_url(concept_url, concept_code, source_url, source_version):
if concept_url and (not concept_code or not source_url):
url_parts = concept_url.split('/concepts/') # /orgs/{org}/sources/{source}(/concepts/){concept}/
if not concept_code:
concept_code = url_parts[1].split('/')[0]
if not source_url:
source_url = url_parts[0] + '/'
if source_url.count('/') == 6: # /orgs/{org}/sources/{source}/{source_version}/
source_version = source_url.split('/')[-1]
source_url = '/'.join(source_url.split('/')[:-1])
return concept_code, source_url, source_version
to_concept_code, to_source_url, to_source_version = expand_concept_url(
to_concept_url, to_concept_code, to_source_url, to_source_version)
from_concept_code, from_source_url, from_source_version = expand_concept_url(
from_concept_url, from_concept_code, from_source_url, from_source_version)

fields = {
'map_type': getvalue(data, 'map_type', None),
'from_concept_code': getvalue(data, 'from_concept_code', None),
'to_concept_code': getvalue(data, 'to_concept_code', None),
'from_concept_code': from_concept_code,
'to_concept_code': to_concept_code,
'from_concept_name': getvalue(data, 'from_concept_name', None),
'to_concept_name': getvalue(data, 'to_concept_name', None),
'retired': getvalue(data, 'retired', False)
}

if self.checksum_type == 'standard':
return {
**fields,
'sort_weight': float(getvalue(data, 'sort_weight', 0)) or None,
'from_source_url': from_source_url,
'from_source_version': from_source_version,
'to_source_url': to_source_url,
'to_source_version': to_source_version,
**{
field: getvalue(data, field, None) or None for field in [
'extras',
'external_id',
'from_source_url',
'from_source_version',
'to_source_url',
'to_source_version'
]
}
}
Expand Down

0 comments on commit dbf174c

Please sign in to comment.