如何从Snomed Postgres Sql数据库中找到关系

时间:2019-07-09 11:34:31

标签: postgresql snomed-ct

问题陈述:

从Snomed CT数据库中提取所有父母,祖父母,子女和孙子

说明:

我正在尝试在本地盒子上建立经过命名的数据库,以提取特定概念(使用concept_id)的关系(所有父母和孩子)。

我已经从https://download.nlm.nih.gov/umls/kss/IHTSDO20190131/SnomedCT_InternationalRF2_PRODUCTION_20190131T120000Z.zip下载了标称数据

然后我使用在https://github.com/IHTSDO/snomed-database-loader/tree/master/PostgreSQL

中找到的脚本将数据导入到 Postgres SQL DB

但是我没有找到这些表之间的任何关系,因此我可以获取具有特定概念ID的父母,祖父母,子女和孙子(我尝试过肺癌 93880001

以下图像包含表结构: enter image description here

我非常感谢您的任何帮助或建议。

1 个答案:

答案 0 :(得分:0)

根据NHS CT Browser(可能无法随处访问),93880001具有三个父级:

  • 肺部恶性肿瘤(疾病)
  • 胸腔内原发性恶性肿瘤(疾病)
  • 呼吸道原发性恶性肿瘤(疾病)

和31个孩子:

  • 肺实质癌(疾病)
  • 肺上皮样血管性血管内皮瘤(疾病)
  • 肺部非霍奇金淋巴瘤(疾病)
  • 非小细胞肺癌(疾病)
  • 依此类推...

查找上级和下级层次结构的方法是使用relationship_f.sourceidrelationship_f.destinationid。但是,原始表不是用户友好的,所以我建议提出一些意见。我已经从this GitHub存储库中的Oracle .sql文件中获取了代码。

首先,我们使用概念ID和首选名称进行查看:

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';

然后我们看一下关系:

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;

因此,要打印出三个父级概念的名称和ID的查询将是:

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

请注意,这实际上返回了三个额外的概念,在线SNOMED浏览器认为它们已过时。我不确定为什么。

要打印出子概念的名称和ID,请用destinationId替换sourceId

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

请注意,这实际上返回了十六个其他概念,在线SNOMED浏览器认为它们已过时。再说一次,我找不到可靠的方法从结果中仅排除这16个。

从这里开始,获取祖父母和孙子女的查询非常简单。