query-da6f816ef0355b906c0a5fc612096e23

rq turtle/ttl

ICD10 handling, case analysis for "infectious disease" and "oncology". Output consists of items without "medical specialty".

Set out in columns for QuickStatements, though itemLabel is not for that. Q788926 means infectious disease, Q162555 oncology.

SELECT DISTINCT ?item ?itemLabel ?ms1 ?ms2 WHERE { ?item wdt:P31 wd:Q12136 . ?item wdt:P494 ?icd . OPTIONAL { ?item wdt:P1995 ?dummy0 } FILTER(!bound(?dummy0)) BIND(SUBSTR(?icd,1,2) AS ?icd1) BIND(xsd:integer(CONCAT("1", SUBSTR(?icd,2,3))) AS ?icd2) BIND((IF (REGEX(?icd1,'A|B'), "Q788926",1/0)) AS ?spec1) #infectious disease BIND((IF (REGEX(?icd1,'C|D') && (STRSTARTS(?icd1, 'C')||(?icd2 < 49)), "Q162555",1/0)) AS ?spec2) #oncology BIND((IF (STRSTARTS(?icd1, 'D') && (49 < ?icd2 && ?icd2 < 90), "Q103824",1/0)) AS ?spec3) #hematology BIND((IF (STRSTARTS(?icd1, 'E') && (?icd2 < 36), "Q162606",1/0)) AS ?spec4) #endocrinology BIND((IF (STRSTARTS(?icd1, 'F') && (?icd2 < 70), "Q7867",1/0)) AS ?spec5) #psychiatry BIND(IF (STRSTARTS(?icd1, 'G'), "Q83042",1/0) AS ?spec6) #neurology BIND((IF (STRSTARTS(?icd1, 'H') && (?icd2 < 60), "Q161437",1/0)) AS ?spec7) #ophthalmology BIND((IF (STRSTARTS(?icd1, 'H') && (59 < ?icd2 && ?icd2 < 96), "Q189553",1/0)) AS ?spec8) #otolaryngology BIND(IF (STRSTARTS(?icd1, 'I'), "Q10379",1/0) AS ?spec9) #cardiology BIND(IF (STRSTARTS(?icd1, 'J'), "Q203337",1/0) AS ?spec10) #pulmonology BIND(IF (STRSTARTS(?icd1, 'K'), "Q120569",1/0) AS ?spec11) #gastroenterology BIND(IF (STRSTARTS(?icd1, 'L'), "Q171171",1/0) AS ?spec12) #dermatology BIND(IF (STRSTARTS(?icd1, 'M'), "Q327657",1/0) AS ?spec13) #rheumatology BIND(IF (STRSTARTS(?icd1, 'N'), "Q105650",1/0) AS ?spec14) #urology BIND(IF (STRSTARTS(?icd1, 'O'), "Q5284418",1/0) AS ?spec15) #obstetrics BIND(IF (STRSTARTS(?icd1, 'Q'), "Q1071953",1/0) AS ?spec16) #medical genetics BIND((IF (REGEX(?icd1,'S|T'), "Q2861470",1/0)) AS ?spec17) #emergency medicine

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

VALUES ?ms1 { "P1995" } VALUES ?ms2 { "Q788926" "Q162555" "Q103824" "Q162606" "Q7867" "Q83042" "Q161437" "Q189553" "Q10379" "Q203337" "Q120569" "Q171171" "Q327657" "Q105650" "Q5284418" "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#>
#ICD10 handling, case analysis for "infectious disease" and "oncology". Output consists of items without "medical specialty".
#Set out in columns for QuickStatements, though itemLabel is not for that. Q788926 means infectious disease, Q162555 oncology.
SELECT DISTINCT ?item ?itemLabel ?ms1 ?ms2
WHERE {
 ?item wdt:P31 wd:Q12136 .
  ?item wdt:P494 ?icd  .
  OPTIONAL { ?item wdt:P1995 ?dummy0 }
  FILTER(!bound(?dummy0))
  BIND(SUBSTR(?icd,1,2) AS ?icd1)
  BIND(xsd:integer(CONCAT("1", SUBSTR(?icd,2,3))) AS ?icd2)
  BIND((IF (REGEX(?icd1,'A|B'), "Q788926",1/0)) AS ?spec1) #infectious disease 
  BIND((IF (REGEX(?icd1,'C|D') &&  (STRSTARTS(?icd1, 'C')||(?icd2 < 49)), "Q162555",1/0)) AS ?spec2) #oncology
  BIND((IF (STRSTARTS(?icd1, 'D') && (49 < ?icd2 && ?icd2 < 90), "Q103824",1/0)) AS ?spec3)  #hematology
  BIND((IF (STRSTARTS(?icd1, 'E') && (?icd2 < 36), "Q162606",1/0)) AS ?spec4) #endocrinology
  BIND((IF (STRSTARTS(?icd1, 'F') && (?icd2 < 70), "Q7867",1/0)) AS ?spec5) #psychiatry
  BIND(IF (STRSTARTS(?icd1, 'G'), "Q83042",1/0) AS ?spec6) #neurology
  BIND((IF (STRSTARTS(?icd1, 'H') && (?icd2 < 60), "Q161437",1/0)) AS ?spec7) #ophthalmology
  BIND((IF (STRSTARTS(?icd1, 'H') && (59 < ?icd2 && ?icd2 < 96), "Q189553",1/0)) AS ?spec8) #otolaryngology
  BIND(IF (STRSTARTS(?icd1, 'I'), "Q10379",1/0) AS ?spec9) #cardiology
  BIND(IF (STRSTARTS(?icd1, 'J'), "Q203337",1/0) AS ?spec10) #pulmonology
  BIND(IF (STRSTARTS(?icd1, 'K'), "Q120569",1/0) AS ?spec11) #gastroenterology
  BIND(IF (STRSTARTS(?icd1, 'L'), "Q171171",1/0) AS ?spec12) #dermatology
  BIND(IF (STRSTARTS(?icd1, 'M'), "Q327657",1/0) AS ?spec13) #rheumatology
  BIND(IF (STRSTARTS(?icd1, 'N'), "Q105650",1/0) AS ?spec14) #urology
  BIND(IF (STRSTARTS(?icd1, 'O'), "Q5284418",1/0) AS ?spec15) #obstetrics
  BIND(IF (STRSTARTS(?icd1, 'Q'), "Q1071953",1/0) AS ?spec16) #medical genetics
  BIND((IF (REGEX(?icd1,'S|T'), "Q2861470",1/0)) AS ?spec17) #emergency medicine

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

  VALUES ?ms1 { "P1995" }
  VALUES ?ms2 { "Q788926" "Q162555" "Q103824" "Q162606" "Q7867" "Q83042" "Q161437" "Q189553" "Q10379" "Q203337" "Q120569" "Q171171" "Q327657" "Q105650" "Q5284418" "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") v5("?icd2") v2("?item"):::projected v24("?ms1"):::projected v25("?ms2"):::projected v6("?spec1") v15("?spec10") v16("?spec11") v17("?spec12") v18("?spec13") v19("?spec14") v20("?spec15") v21("?spec16") v22("?spec17") v7("?spec2") v8("?spec3") 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:P494"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P1995".-> v1 end bind1[/"substring(?icd,'1^^xsd:integer','2^^xsd:integer')"/] v3 --o bind1 bind1 --as--o v4 bind2[/"http://www.w3.org/2001/XMLSchema#integer(concat('1',substring(?icd,'2^^xsd:integer','3^^xsd:integer')))"/] v3 --o bind2 bind2 --as--o v5 bind3[/"if(regex(?icd1,'A|B'),'Q788926','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind3 bind3 --as--o v6 bind4[/"if(regex(?icd1,'C|D')(starts-with(?icd1,'C') || ?icd2 < '49^^xsd:integer'),'Q162555','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind4 v5 --o bind4 bind4 --as--o v7 bind5[/"if(starts-with(?icd1,'D')'49^^xsd:integer' < ?icd2?icd2 < '90^^xsd:integer','Q103824','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind5 v5 --o bind5 bind5 --as--o v8 bind6[/"if(starts-with(?icd1,'E')?icd2 < '36^^xsd:integer','Q162606','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind6 v5 --o bind6 bind6 --as--o v9 bind7[/"if(starts-with(?icd1,'F')?icd2 < '70^^xsd:integer','Q7867','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind7 v5 --o bind7 bind7 --as--o v10 bind8[/"if(starts-with(?icd1,'G'),'Q83042','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind8 bind8 --as--o v11 bind9[/"if(starts-with(?icd1,'H')?icd2 < '60^^xsd:integer','Q161437','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind9 v5 --o bind9 bind9 --as--o v12 bind10[/"if(starts-with(?icd1,'H')'59^^xsd:integer' < ?icd2?icd2 < '96^^xsd:integer','Q189553','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind10 v5 --o bind10 bind10 --as--o v13 bind11[/"if(starts-with(?icd1,'I'),'Q10379','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind11 bind11 --as--o v14 bind12[/"if(starts-with(?icd1,'J'),'Q203337','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind12 bind12 --as--o v15 bind13[/"if(starts-with(?icd1,'K'),'Q120569','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind13 bind13 --as--o v16 bind14[/"if(starts-with(?icd1,'L'),'Q171171','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind14 bind14 --as--o v17 bind15[/"if(starts-with(?icd1,'M'),'Q327657','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind15 bind15 --as--o v18 bind16[/"if(starts-with(?icd1,'N'),'Q105650','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind16 bind16 --as--o v19 bind17[/"if(starts-with(?icd1,'O'),'Q5284418','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind17 bind17 --as--o v20 bind18[/"if(starts-with(?icd1,'Q'),'Q1071953','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind18 bind18 --as--o v21 bind19[/"if(regex(?icd1,'S|T'),'Q2861470','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind19 bind19 --as--o v22 bind20[/"?spec1?spec2?spec3?spec4?spec5?spec6?spec7?spec8?spec9?spec10?spec11?spec12?spec13?spec14?spec15?spec16?spec17'000000^^xsd:integer'"/] v6 --o bind20 v7 --o bind20 v8 --o bind20 v9 --o bind20 v10 --o bind20 v11 --o bind20 v12 --o bind20 v13 --o bind20 v14 --o bind20 v15 --o bind20 v16 --o bind20 v17 --o bind20 v18 --o bind20 v19 --o bind20 v20 --o bind20 v21 --o bind20 v22 --o bind20 bind20 --as--o v25 bind21[/VALUES ?ms1/] bind21-->v24 bind210(["P1995"]) bind210 --> bind21 bind22[/VALUES ?ms2/] bind22-->v25 bind220(["Q788926"]) bind220 --> bind22 bind221(["Q162555"]) bind221 --> bind22 bind222(["Q103824"]) bind222 --> bind22 bind223(["Q162606"]) bind223 --> bind22 bind224(["Q7867"]) bind224 --> bind22 bind225(["Q83042"]) bind225 --> bind22 bind226(["Q161437"]) bind226 --> bind22 bind227(["Q189553"]) bind227 --> bind22 bind228(["Q10379"]) bind228 --> bind22 bind229(["Q203337"]) bind229 --> bind22 bind2210(["Q120569"]) bind2210 --> bind22 bind2211(["Q171171"]) bind2211 --> bind22 bind2212(["Q327657"]) bind2212 --> bind22 bind2213(["Q105650"]) bind2213 --> bind22 bind2214(["Q5284418"]) bind2214 --> bind22 bind2215(["Q1071953"]) bind2215 --> bind22 bind2216(["Q2861470"]) bind2216 --> bind22 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end