query-755f85ff6567134f3bff00127b8129e3
ICD9 handling SELECT DISTINCT ?item ?itemLabel
?icd ?icd2 ?icd3 removed so that SELECT DISTINCT works
WHERE { ?item wdt:P31 wd:Q12136 . ?item wdt:P493 ?icd . OPTIONAL { ?item wdt:P1995 ?dummy0 } FILTER(!bound(?dummy0)) BIND(SUBSTR(?icd,1,3) AS ?icd1) #drop decimal point and anything after BIND(CONCAT("1",?icd1) AS ?icd2) #add initial digit 1 to preserve initial zeroes BIND(xsd:integer(?icd2) AS ?icd3) # casting function to turn string to integer FILTER(1000 < ?icd3 && ?icd3 <1140) SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }
Use at
- https://query.wikidata.org/sparql
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
SELECT DISTINCT ?item ?itemLabel
#?icd ?icd2 ?icd3 removed so that SELECT DISTINCT works
WHERE {
?item wdt:P31 wd:Q12136 .
?item wdt:P493 ?icd .
OPTIONAL { ?item wdt:P1995 ?dummy0 }
FILTER(!bound(?dummy0))
BIND(SUBSTR(?icd,1,3) AS ?icd1) #drop decimal point and anything after
BIND(CONCAT("1",?icd1) AS ?icd2) #add initial digit 1 to preserve initial zeroes
BIND(xsd:integer(?icd2) AS ?icd3) # casting function to turn string to integer
FILTER(1000 < ?icd3 && ?icd3 <1140)
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;
v2("?dummy0")
v4("?icd")
v5("?icd1")
v6("?icd2")
v7("?icd3")
v3("?item"):::projected
c8(["bd:serviceParam"]):::iri
c10(["en"]):::literal
c4(["wd:Q12136"]):::iri
f0[["'1000^^xsd:integer' < ?icd3?icd3 < '1140^^xsd:integer'"]]
f0 --> v7
f1[["not bound(?dummy0)"]]
f1 --> v2
v3 --"wdt:P31"--> c4
v3 --"wdt:P493"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P1995".-> v2
end
bind2[/"substring(?icd,'1^^xsd:integer','3^^xsd:integer')"/]
v4 --o bind2
bind2 --as--o v5
bind3[/"concat('1',?icd1)"/]
v5 --o bind3
bind3 --as--o v6
bind4[/"http://www.w3.org/2001/XMLSchema#integer(?icd2)"/]
v6 --o bind4
bind4 --as--o v7
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end