Skip to content

Commit

Permalink
Merge pull request #97 from FHIR/terminologyUtility
Browse files Browse the repository at this point in the history
Terminology utility
  • Loading branch information
rhdolin authored Nov 7, 2024
2 parents 81c9e68 + 0f730db commit 1150e14
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/api_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ paths:
type: string
pattern: '^\s*[Nn][Pp]_\d{4,10}(\.)?(\d{1,2})?\s*$'
example: "NP_000005.3"

/utilities/find-the-gene:
get:
description: |-
Expand All @@ -1305,6 +1306,41 @@ paths:
pattern: '^\s*[Nn][Cc]_\d{4,10}(\.)(\d{1,2}):\d{1,10}-\d{1,10}\s*$'
example: "NC_000001.11:11794399-11794400"

/utilities/terminology-translation:
get:
description: |-
This utility demonstrates terminology translations SNOMED to MedGen and DiseaseOntology; ICD10 to MedGen and DiseaseOntology; RxNorm to NCIt.
summary: "Translate from one code system to another"
operationId: "app.utilities_endpoints.translate_terminology"
tags:
- "Operations Utilities (not part of balloted HL7 Operations)"
responses:
'200':
description: "Returns matching codes in target code system(s)."
content:
application/json:
schema:
type: object
parameters:
- name: codeSystem
in: query
required: true
description: Code system for code to be translated.
schema:
type: string
enum:
- "http://www.nlm.nih.gov/research/umls/rxnorm"
- "http://snomed.info/sct"
- "http://hl7.org/fhir/sid/icd-10"
example: "http://snomed.info/sct"
- name: code
in: query
schema:
type: string
example: '126949007'
required: true
description: The code to be translated.

tags:
- name: Subject Genotype Operations
- name: Subject Phenotype Operations
Expand Down
101 changes: 101 additions & 0 deletions app/utilities_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from flask import abort, jsonify
from collections import OrderedDict
from app import common
import requests


def fetch_concept_map(mapID):
url = f"http://hapi.fhir.org/baseR4/ConceptMap/{mapID}"
headers = {'Accept': 'application/json'}
return requests.get(url, headers=headers)


def get_feature_coordinates(
Expand Down Expand Up @@ -189,3 +196,97 @@ def find_the_gene(range=None):
output.append(ord_dict)

return (jsonify(output))


def translate_terminology(codeSystem, code):
# validate input parameters
if codeSystem not in ['http://www.nlm.nih.gov/research/umls/rxnorm', 'http://snomed.info/sct', 'http://hl7.org/fhir/sid/icd-10']:
return "unrecognized code system"
response = [{}]

# process rxnorm input
if codeSystem == 'http://www.nlm.nih.gov/research/umls/rxnorm':
MapRxNorm = fetch_concept_map(44872525)
if MapRxNorm.status_code == 200:
MapRxNorm = MapRxNorm.json()
for element in MapRxNorm["group"][0]["element"]:
if element["code"] == code:
response[0]["outcome"] = 'match found'
response[0]["code"] = element["target"][0]["code"]
response[0]["system"] = 'https://ncithesaurus.nci.nih.gov/'
response[0]["display"] = element["target"][0]["display"]
return response
response[0]["outcome"] = 'no match found'
response[0]["system"] = 'https://ncithesaurus.nci.nih.gov/'
return response
else:
abort(500, "HAPI server error")

# process snomed input, return disease ontology code AND medgen
if codeSystem == 'http://snomed.info/sct':
Mapsnomed = fetch_concept_map(44947014)
if Mapsnomed.status_code == 200:
Mapsnomed = Mapsnomed.json()
for element in Mapsnomed["group"][0]["element"]:
if element["code"] == code:
response[0]["outcome"] = 'match found'
response[0]["code"] = element["target"][0]["code"]
response[0]["system"] = 'https://disease-ontology.org/'
response[0]["display"] = element["target"][0]["display"]
break
response[0]["outcome"] = 'no match found'
response[0]["system"] = 'https://disease-ontology.org/'
else:
abort(500, "HAPI server error")

Mapsnomed = fetch_concept_map(44872524)
if Mapsnomed.status_code == 200:
Mapsnomed = Mapsnomed.json()
response.append({})
for element in Mapsnomed["group"][0]["element"]:
if element["code"] == code:
response[1]["outcome"] = 'match found'
response[1]["code"] = element["target"][0]["code"]
response[1]["system"] = 'https://www.ncbi.nlm.nih.gov/medgen/'
response[1]["display"] = element["target"][0]["display"]
break
response[1]["outcome"] = 'no match found'
response[1]["system"] = 'https://www.ncbi.nlm.nih.gov/medgen/'
else:
abort(500, "HAPI server error")
return response

# process ICD10 input, return disease ontology AND medgen codes
if codeSystem == 'http://hl7.org/fhir/sid/icd-10':
code = code.upper().replace(".", "")
MapICD10 = fetch_concept_map(44872527)
if MapICD10.status_code == 200:
MapICD10 = MapICD10.json()
for element in MapICD10["group"][0]["element"]:
if element["code"] == code:
response[0]["outcome"] = 'match found'
response[0]["code"] = element["target"][0]["code"]
response[0]["system"] = 'https://disease-ontology.org/'
response[0]["display"] = element["target"][0]["display"]
break
response[0]["outcome"] = 'no match found'
response[0]["system"] = 'https://disease-ontology.org/'
else:
abort(500, "HAPI server error")

MapICD10 = fetch_concept_map(44872523)
if MapICD10.status_code == 200:
MapICD10 = MapICD10.json()
response.append({})
for element in MapICD10["group"][0]["element"]:
if element["code"] == code:
response[1]["outcome"] = "match found"
response[1]["code"] = element["target"][0]["code"]
response[1]["system"] = "https://www.ncbi.nlm.nih.gov/medgen/"
response[1]["display"] = element["target"][0]["display"]
break
response[1]["outcome"] = "no match found"
response[1]["system"] = "https://www.ncbi.nlm.nih.gov/medgen/"
else:
abort(500, "HAPI server error")
return response

0 comments on commit 1150e14

Please sign in to comment.