query-3682cc9b7b16960b8dda7937b45a9309

rq turtle/ttl

ICD9 handling. This prototype does a case analysis with three cases. Output in two columns adapted to QuickStatement 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) #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) BIND((IF (1279 < ?icd1 && ?icd1 <1290, "Q103824",1/0)) AS ?spec3)

BIND(COALESCE(?spec1,?spec2,?spec3,2) AS ?ms2) VALUES ?ms1 { "P1995" } VALUES ?ms2 { "Q788926" "Q162555" "Q103824" } 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 prototype does a case analysis with three cases. Output in two columns adapted to QuickStatement 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)
  #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)
  BIND((IF (1279 < ?icd1 && ?icd1 <1290, "Q103824",1/0)) AS ?spec3)

  BIND(COALESCE(?spec1,?spec2,?spec3,2) AS ?ms2)
  VALUES ?ms1 { "P1995" }
  VALUES ?ms2 { "Q788926" "Q162555" "Q103824" }
  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 v9("?ms1"):::projected v10("?ms2"):::projected v5("?spec1") v6("?spec2") v7("?spec3") 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('1279^^xsd:integer' < ?icd1?icd1 < '1290^^xsd:integer','Q103824','1^^xsd:integer' / '0^^xsd:integer')"/] v4 --o bind4 bind4 --as--o v7 bind5[/"?spec1?spec2?spec3'2^^xsd:integer'"/] v5 --o bind5 v6 --o bind5 v7 --o bind5 bind5 --as--o v10 bind6[/VALUES ?ms1/] bind6-->v9 bind60(["P1995"]) bind60 --> bind6 bind7[/VALUES ?ms2/] bind7-->v10 bind70(["Q788926"]) bind70 --> bind7 bind71(["Q162555"]) bind71 --> bind7 bind72(["Q103824"]) bind72 --> bind7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end