Kor03d

Untitled

Aug 7th, 2019
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. drop index if exists idx_crs
  2. ;
  3. create index idx_crs on concept_relationship_stage (concept_code_1, vocabulary_id_1, concept_code_2, vocabulary_id_2)
  4. ;
  5. analyze concept_relationship_stage
  6. ;
  7. --to do:
  8. -- Unify attribute-relationship-ids; LOINC has 5 up to attributes, can't have more
  9. -- add other metrics
  10. -- write filters on conflicting components; use filters similar to icd10pcs
  11. --optimize w/ indices
  12. select --relationship_id
  13.     l1.*,
  14.     x1.*
  15. from concept_stage l1 --LOINC concept
  16. join concept_relationship_stage r1 on --R1 is LOINC concept vs. SNOMED attribute (Specimen)
  17.     (r1.concept_code_1, r1.vocabulary_id_1) = (l1.concept_code, l1.vocabulary_id) and
  18.     l1.vocabulary_id = 'LOINC' and
  19.     r1.relationship_id = 'Has direct site' --aka LOINC 'System'
  20. join concept sa1 on --SNOMED attribute concept
  21.     (r1.concept_code_2, r1.vocabulary_id_2) = (sa1.concept_code, sa1.vocabulary_id) and
  22.     sa1.vocabulary_id = 'SNOMED'
  23. join concept_relationship_stage r2 on --R2 is LOINC concept vs. SNOMED attribute (Component)
  24.     (r2.concept_code_1, r2.vocabulary_id_1) = (l1.concept_code, l1.vocabulary_id) and
  25.     r2.relationship_id = 'Has component' --aka LOINC 'Component'
  26. join concept sa2 on --SNOMED attribute concept
  27.     (r2.concept_code_2, r2.vocabulary_id_2) = (sa2.concept_code, sa2.vocabulary_id) and
  28.     sa2.vocabulary_id = 'SNOMED'
  29. join concept_relationship t1 on --pick up SNOMED combination
  30.     t1.concept_id_2 = sa1.concept_id
  31. join concept_relationship t2 on
  32.     t1.concept_id_1 = t2.concept_id_1 and
  33.     t2.concept_id_2 = sa2.concept_id
  34. join concept x1 on
  35.     x1.concept_id = t1.concept_id_1 and
  36.     x1.vocabulary_id = 'SNOMED'
  37. join devv5.concept_ancestor a on
  38.     a.ancestor_concept_id = 4297090 and -- SNOMED "Evaluation"
  39.     a.descendant_concept_id = x1.concept_id
  40. where
  41.     sa2.concept_id != 4146516 --SNOMED generic 'component'
  42. limit 10
  43. ;
Advertisement
Add Comment
Please, Sign In to add comment