How to find relationship from Snomed Postgres Sql Database

笑着哭i 提交于 2019-12-11 08:49:21

问题


Problem Statement:

Extract all parents, grandparents, child, and grandchild from Snomed CT database

Description:

I am trying to set up the snomed database on my local box to extract relationships (all parents and child) for a particular concept (using concept_id).

I have downloaded snomed data from https://download.nlm.nih.gov/umls/kss/IHTSDO20190131/SnomedCT_InternationalRF2_PRODUCTION_20190131T120000Z.zip

Then I imported data into Postgres SQL DB using a script which I found here https://github.com/IHTSDO/snomed-database-loader/tree/master/PostgreSQL

But I didn't find any relationship between these tables so that I can fetch parents, grandparents, children and grandchildren for a particular concept id (I tried with lung cancer 93880001)

Following image contains table structure:

I really appreciate any help or suggestions.


回答1:


According to the NHS CT Browser, which may not be accessible from everywhere, 93880001 has three parents:

  • Malignant tumor of lung (disorder)
  • Primary malignant neoplasm of intrathoracic organs (disorder)
  • Primary malignant neoplasm of respiratory tract (disorder)

and 31 children:

  • Carcinoma of lung parenchyma (disorder)
  • Epithelioid hemangioendothelioma of lung (disorder)
  • Non-Hodgkin's lymphoma of lung (disorder)
  • Non-small cell lung cancer (disorder)
  • and so on...

The way to find higher and lower levels of the hierarchy is to use relationship_f.sourceid and relationship_f.destinationid. However, the raw tables are not user friendly so I would suggest making some views. I have taken the code from the Oracle .sql files in this GitHub repo.

First, we make a view with concept IDs and preferred names:

create view conceptpreferredname as
SELECT distinct c.id conceptId, d.term preferredName, d.id descriptionId
FROM postgres.snomedct.concept_f c
inner JOIN postgres.snomedct.description_f d
  ON c.id = d.conceptId
  AND d.active = '1'
  AND d.typeId = '900000000000013009'
inner JOIN postgres.snomedct.langrefset_f l
  ON d.id = l.referencedComponentId
  AND l.active = '1'
  AND l.refSetId = '900000000000508004'  -- GB English
  AND l.acceptabilityId = '900000000000548007';

Then we make a view of relationships:

CREATE VIEW relationshipwithnames AS
SELECT id, effectiveTime, active,
    moduleId, cpn1.preferredName moduleIdName,
    sourceId, cpn2.preferredName sourceIdName,
    destinationId, cpn3.preferredName destinationIdName,
    relationshipGroup,
    typeId, cpn4.preferredName typeIdName,
    characteristicTypeId, cpn5.preferredName characteristicTypeIdName,
    modifierId, cpn6.preferredName modifierIdName
from postgres.snomedct.relationship_f relationship,
    conceptpreferredname cpn1,
    conceptpreferredname cpn2,
    conceptpreferredname cpn3,
    conceptpreferredname cpn4,
    conceptpreferredname cpn5,
    conceptpreferredname cpn6
WHERE moduleId = cpn1.conceptId
AND sourceId = cpn2.conceptId
AND destinationId = cpn3.conceptId
AND typeId = cpn4.conceptId
AND characteristicTypeId = cpn5.conceptId
AND modifierId = cpn6.conceptId;

So a query to print out the names and ids of the three parent concepts would be:

select *
from relationshipwithnames r
where r.sourceId = '93880001'
and r.active = '1'
and r.typeIdName = 'Is a';

Note that this actually returns three extra concepts, which the online SNOMED browser thinks are obsolete. I am not sure why.

To print out the names and ids of child concepts, replace destinationId with sourceId:

select *
from relationshipwithnames r
where r.destinationId = '93880001'
and r.active = '1'
and r.typeIdName = 'Is a';

Note that this actually returns sixteen extra concepts, which the online SNOMED browser thinks are obsolete. Again, I cannot find a reliable way to exclude only these sixteen from the results.

From here, queries to get grandparents and grandchildren are straightforward.



来源:https://stackoverflow.com/questions/56951658/how-to-find-relationship-from-snomed-postgres-sql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!