query-5fe047360820dbc6fe1a2edb91931e73

rq turtle/ttl

ICD9 handling. This query does a case analysis with 16 cases. Output in columns is adapted to QuickStatements input. SELECT DISTINCT ?item ?itemLabel ?ms1 ?ms2 WHERE { ?item wdt:P31 wd:Q12136 . ?item wdt:P493 ?icd . OPTIONAL { ?item wdt:P1995 ?dummy0 } FILTER(!bound(?dummy0))

BIND(xsd:integer(CONCAT("1",SUBSTR(?icd,1,3))) AS ?icd1) #One-line processing of ICD-9 code into integer. Currently fails in a few alphanumeric cases. BIND((IF (1000 < ?icd1 && ?icd1 <1140, "Q788926",1/0)) AS ?spec1) #infectious disease specialty #Dividing by zero, deliberate introduction of error in the "else" part of IF. This causes a desired fallback in COALESCE. BIND((IF (1139 < ?icd1 && ?icd1 <1240, "Q162555",1/0)) AS ?spec2) #oncology BIND((IF (1239 < ?icd1 && ?icd1 <1260, "Q162606",1/0)) AS ?spec3a) #endocrinology BIND((IF (1278 < ?icd1 && ?icd1 <1280, "Q101929",1/0)) AS ?spec3b) #immunology BIND((IF (1279 < ?icd1 && ?icd1 <1290, "Q103824",1/0)) AS ?spec4) #hematology BIND((IF (1289 < ?icd1 && ?icd1 <1320, "Q7867",1/0)) AS ?spec5) #psychiatry BIND((IF (1319 < ?icd1 && ?icd1 <1390, "Q83042",1/0)) AS ?spec6) #neurology BIND((IF (1389 < ?icd1 && ?icd1 <1460, "Q10379",1/0)) AS ?spec7) #cardiology BIND((IF (1459 < ?icd1 && ?icd1 <1520, "Q203337",1/0)) AS ?spec8) #pulmonology BIND((IF (1519 < ?icd1 && ?icd1 <1580, "Q120569",1/0)) AS ?spec9) #gastroenterology BIND((IF (1579 < ?icd1 && ?icd1 <1630, "Q105650",1/0)) AS ?spec10) #urology BIND((IF (1629 < ?icd1 && ?icd1 <1680, "Q5284418",1/0)) AS ?spec11) #obstetrics BIND((IF (1679 < ?icd1 && ?icd1 <1710, "Q171171",1/0)) AS ?spec12) #dermatology BIND((IF (1709 < ?icd1 && ?icd1 <1740, "Q327657",1/0)) AS ?spec13) #rheumatology BIND((IF (1739 < ?icd1 && ?icd1 <1760, "Q1071953",1/0)) AS ?spec14) #medical genetics BIND((IF (1799 < ?icd1 && ?icd1 <2000, "Q2861470",1/0)) AS ?spec15) #emergency medicine

BIND(COALESCE(?spec1,?spec2,?spec3a,?spec3b,?spec4,?spec5,?spec6,?spec7,?spec8,?spec9,?spec10,?spec11,?spec12,?spec13,?spec14,?spec15,000000) AS ?ms2)

VALUES ?ms1 { "P1995" } VALUES ?ms2 { "Q788926" "Q162555" "Q162606" "Q101929" "Q103824" "Q7867" "Q83042" "Q10379" "Q203337" "Q120569" "Q105650" "Q5284418" "Q171171" "Q327657" "Q1071953" "Q2861470"} SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#ICD9 handling. This query does a case analysis with 16 cases. Output in columns is adapted to QuickStatements input.
SELECT DISTINCT ?item ?itemLabel ?ms1 ?ms2
WHERE {
 ?item wdt:P31 wd:Q12136 .
  ?item wdt:P493 ?icd  .
  OPTIONAL { ?item wdt:P1995 ?dummy0 }
  FILTER(!bound(?dummy0))

  BIND(xsd:integer(CONCAT("1",SUBSTR(?icd,1,3))) AS ?icd1)
  #One-line processing of ICD-9 code into integer. Currently fails in a few alphanumeric cases.
  BIND((IF (1000 < ?icd1 && ?icd1 <1140, "Q788926",1/0)) AS ?spec1) #infectious disease specialty
  #Dividing by zero, deliberate introduction of error in the "else" part of IF. This causes a desired fallback in COALESCE.
  BIND((IF (1139 < ?icd1 && ?icd1 <1240, "Q162555",1/0)) AS ?spec2) #oncology
  BIND((IF (1239 < ?icd1 && ?icd1 <1260, "Q162606",1/0)) AS ?spec3a) #endocrinology
  BIND((IF (1278 < ?icd1 && ?icd1 <1280, "Q101929",1/0)) AS ?spec3b) #immunology
  BIND((IF (1279 < ?icd1 && ?icd1 <1290, "Q103824",1/0)) AS ?spec4) #hematology
  BIND((IF (1289 < ?icd1 && ?icd1 <1320, "Q7867",1/0)) AS ?spec5) #psychiatry
  BIND((IF (1319 < ?icd1 && ?icd1 <1390, "Q83042",1/0)) AS ?spec6) #neurology
  BIND((IF (1389 < ?icd1 && ?icd1 <1460, "Q10379",1/0)) AS ?spec7) #cardiology
  BIND((IF (1459 < ?icd1 && ?icd1 <1520, "Q203337",1/0)) AS ?spec8) #pulmonology
  BIND((IF (1519 < ?icd1 && ?icd1 <1580, "Q120569",1/0)) AS ?spec9) #gastroenterology
  BIND((IF (1579 < ?icd1 && ?icd1 <1630, "Q105650",1/0)) AS ?spec10) #urology
  BIND((IF (1629 < ?icd1 && ?icd1 <1680, "Q5284418",1/0)) AS ?spec11) #obstetrics
  BIND((IF (1679 < ?icd1 && ?icd1 <1710, "Q171171",1/0)) AS ?spec12) #dermatology
  BIND((IF (1709 < ?icd1 && ?icd1 <1740, "Q327657",1/0)) AS ?spec13) #rheumatology
  BIND((IF (1739 < ?icd1 && ?icd1 <1760, "Q1071953",1/0)) AS ?spec14) #medical genetics
  BIND((IF (1799 < ?icd1 && ?icd1 <2000, "Q2861470",1/0)) AS ?spec15) #emergency medicine

  BIND(COALESCE(?spec1,?spec2,?spec3a,?spec3b,?spec4,?spec5,?spec6,?spec7,?spec8,?spec9,?spec10,?spec11,?spec12,?spec13,?spec14,?spec15,000000) AS ?ms2)

  VALUES ?ms1 { "P1995" }
  VALUES ?ms2 { "Q788926" "Q162555" "Q162606" "Q101929" "Q103824" "Q7867" "Q83042" "Q10379" "Q203337" "Q120569" "Q105650" "Q5284418" "Q171171" "Q327657" "Q1071953" "Q2861470"}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
      }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?dummy0") v3("?icd") v4("?icd1") v2("?item"):::projected v22("?ms1"):::projected v23("?ms2"):::projected v5("?spec1") v15("?spec10") v16("?spec11") v17("?spec12") v18("?spec13") v19("?spec14") v20("?spec15") v6("?spec2") v7("?spec3a") v8("?spec3b") v9("?spec4") v10("?spec5") v11("?spec6") v12("?spec7") v13("?spec8") v14("?spec9") c6(["bd:serviceParam"]):::iri c8(["en"]):::literal c2(["wd:Q12136"]):::iri f0[["not bound(?dummy0)"]] f0 --> v1 v2 --"wdt:P31"--> c2 v2 --"wdt:P493"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P1995".-> v1 end bind1[/"http://www.w3.org/2001/XMLSchema#integer(concat('1',substring(?icd,'1^^xsd:integer','3^^xsd:integer')))"/] v3 --o bind1 bind1 --as--o v4 bind2[/"if('1000^^xsd:integer' < ?icd1?icd1 < '1140^^xsd:integer','Q788926','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind2 bind2 --as--o v5 bind3[/"if('1139^^xsd:integer' < ?icd1?icd1 < '1240^^xsd:integer','Q162555','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind3 bind3 --as--o v6 bind4[/"if('1239^^xsd:integer' < ?icd1?icd1 < '1260^^xsd:integer','Q162606','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind4 bind4 --as--o v7 bind5[/"if('1278^^xsd:integer' < ?icd1?icd1 < '1280^^xsd:integer','Q101929','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind5 bind5 --as--o v8 bind6[/"if('1279^^xsd:integer' < ?icd1?icd1 < '1290^^xsd:integer','Q103824','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind6 bind6 --as--o v9 bind7[/"if('1289^^xsd:integer' < ?icd1?icd1 < '1320^^xsd:integer','Q7867','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind7 bind7 --as--o v10 bind8[/"if('1319^^xsd:integer' < ?icd1?icd1 < '1390^^xsd:integer','Q83042','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind8 bind8 --as--o v11 bind9[/"if('1389^^xsd:integer' < ?icd1?icd1 < '1460^^xsd:integer','Q10379','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind9 bind9 --as--o v12 bind10[/"if('1459^^xsd:integer' < ?icd1?icd1 < '1520^^xsd:integer','Q203337','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind10 bind10 --as--o v13 bind11[/"if('1519^^xsd:integer' < ?icd1?icd1 < '1580^^xsd:integer','Q120569','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind11 bind11 --as--o v14 bind12[/"if('1579^^xsd:integer' < ?icd1?icd1 < '1630^^xsd:integer','Q105650','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind12 bind12 --as--o v15 bind13[/"if('1629^^xsd:integer' < ?icd1?icd1 < '1680^^xsd:integer','Q5284418','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind13 bind13 --as--o v16 bind14[/"if('1679^^xsd:integer' < ?icd1?icd1 < '1710^^xsd:integer','Q171171','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind14 bind14 --as--o v17 bind15[/"if('1709^^xsd:integer' < ?icd1?icd1 < '1740^^xsd:integer','Q327657','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind15 bind15 --as--o v18 bind16[/"if('1739^^xsd:integer' < ?icd1?icd1 < '1760^^xsd:integer','Q1071953','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind16 bind16 --as--o v19 bind17[/"if('1799^^xsd:integer' < ?icd1?icd1 < '2000^^xsd:integer','Q2861470','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind17 bind17 --as--o v20 bind18[/"?spec1?spec2?spec3a?spec3b?spec4?spec5?spec6?spec7?spec8?spec9?spec10?spec11?spec12?spec13?spec14?spec15'000000^^xsd:integer'"/] v5 --o bind18 v6 --o bind18 v7 --o bind18 v8 --o bind18 v9 --o bind18 v10 --o bind18 v11 --o bind18 v12 --o bind18 v13 --o bind18 v14 --o bind18 v15 --o bind18 v16 --o bind18 v17 --o bind18 v18 --o bind18 v19 --o bind18 v20 --o bind18 bind18 --as--o v23 bind19[/VALUES ?ms1/] bind19-->v22 bind190(["P1995"]) bind190 --> bind19 bind20[/VALUES ?ms2/] bind20-->v23 bind200(["Q788926"]) bind200 --> bind20 bind201(["Q162555"]) bind201 --> bind20 bind202(["Q162606"]) bind202 --> bind20 bind203(["Q101929"]) bind203 --> bind20 bind204(["Q103824"]) bind204 --> bind20 bind205(["Q7867"]) bind205 --> bind20 bind206(["Q83042"]) bind206 --> bind20 bind207(["Q10379"]) bind207 --> bind20 bind208(["Q203337"]) bind208 --> bind20 bind209(["Q120569"]) bind209 --> bind20 bind2010(["Q105650"]) bind2010 --> bind20 bind2011(["Q5284418"]) bind2011 --> bind20 bind2012(["Q171171"]) bind2012 --> bind20 bind2013(["Q327657"]) bind2013 --> bind20 bind2014(["Q1071953"]) bind2014 --> bind20 bind2015(["Q2861470"]) bind2015 --> bind20 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end