Published 9th July 2011
Type SPARQL Endpoint
Users 29

SPARQL Endpoint

This API provides a way to perform structure queries against the NHS Organization dataset. E.g. finding all sites associated with a given primary care trust, listing organizations of a specific type, etc.

See the example query section further down this page for a list of useful queries to run against the dataset.

Documentation

Endpoint URL

http://api.kasabi.com/dataset/nhs-organization/apis/sparql
Login to test this query using our experimental API explorer

Authentication

You will need your API key in order to authenticate to this API. You have two options for authentication:

  • By URL Parameter -- add a apikey parameter to your request URL, with your key as the value
  • By Request Header -- add a custom HTTP header called X_KASABI_APIKEY to your HTTP request, with your key as the value

For more information on Kasabi authentication options read the authentication documentation. Your API key will need to be authorized to use this service.

Parameters

This API supports the following request parameters:

Parameter NameParameter Value(s)Required?Notes
queryURL encoded SPARQL queryYesThis is the query to execute against the dataset
outputShort name for desired response formatNoSupports selecting response format using url parameter rather than HTTP Accept header.

HTTP Response Codes

Clients should be prepared to receive any valid HTTP response code. The following table lists the most frequently used codes

CodeMeaning
200 OKSuccessful Request
400 Bad RequestMissing or malformed SPARQL query
401 Not AuthorizedAPI key is not authorized to access the data

Please also review our additional notes on response codes.

Response Formats

Query Type Response Format Accept Header output parameter Notes
SELECT or ASK application/sparql-results+json application/sparql-results+json json Return results in SPARQL JSON results format
SELECT or ASK application/sparql-results+xml application/sparql-results+json xml Return results in SPARQL XML results format
CONSTRUCT or DESCRIBE application/rdf application/rdf rdf (or xml) Return results as RDF/XML
CONSTRUCT or DESCRIBE application/rdf application/rdf rdf (or xml) Return results as RDF/XML
CONSTRUCT or DESCRIBE application/json application/json json Return results as RDF/JSON
CONSTRUCT or DESCRIBE text/turtle text/turtle turtle Return results as Turtle
CONSTRUCT or DESCRIBE text/plain text/plain ntriples Return results as NTriples

Sample Queries

This query lists the name and code for all UK Primary Care Trusts. The query can be easily amended to select a different type of resource, e.g. nhs:CareTrust, nhs:AcuteTrust, nhs:Dispensary, etc.

Query: 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> SELECT ?code ?name WHERE { ?org a nhs:PrimaryCareTrust; org:identifier ?code; rdfs:label ?name. } ORDER BY ?code
Login to test this query using our experimental API explorer Permalink to this sample query

Provided with the unique NHS ODS code for an Organization, this query finds the name of that site and its primary address. An organization may actually have several sites associated with it, but this query just returns the main site, which will typically be the head-quarters.

Query: 
PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> SELECT ?name ?address WHERE { ?org org:identifier "5E1"^^nhs:odsCode; rdfs:label ?name; org:hasPrimarySite ?site. ?site org:siteAddress ?vcard. ?vcard vcard:adr ?adr. ?adr rdfs:label ?address. }
Login to test this query using our experimental API explorer Permalink to this sample query

This query returns the URI, code and name for all organizations associated with a specific Primary Care Trust. The query is written to allow the PCT to be identified by its unique code, rather than its URI.

Query: 
PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?org ?code ?name WHERE { ?org org:identifier ?code; rdfs:label ?name; nhs:primaryCareTrust ?trust. ?trust org:identifier "5E1"^^nhs:odsCode. }
Login to test this query using our experimental API explorer Permalink to this sample query

This query finds the URI, code, and name for all General Practices associated with a specific post code. The post code is specified using an Ordnance Survey URI.

Query: 
PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> PREFIX os: <http://data.ordnancesurvey.co.uk/ontology/postcode/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?org ?code ?name WHERE { ?org a nhs:GeneralPractice; org:identifier ?code; rdfs:label ?name; org:hasSite ?site. ?site os:postcode <http://data.ordnancesurvey.co.uk/id/postcodeunit/TS181HU>. }
Login to test this query using our experimental API explorer Permalink to this sample query

This query finds all General Practices associated with a specific post code and then the GPs associated with each practice.

Query: 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> PREFIX os: <http://data.ordnancesurvey.co.uk/ontology/postcode/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?doctor ?practice WHERE { ?org a nhs:GeneralPractice; org:hasSite ?site; rdfs:label ?practice. #limit to postcode of interest ?site os:postcode <http://data.ordnancesurvey.co.uk/id/postcodeunit/TS181HU>. #find gps who are members of the practices found ?gp org:memberOf ?org; foaf:name ?doctor. } ORDER BY ?doctor
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?org ?name ?twitter WHERE { ?org rdfs:label ?name; foaf:holdsAccount ?twitter. ?twitter foaf:accountServiceHomepage <http://twitter.com> }
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?org ?name ?flickr WHERE { ?org rdfs:label ?name; foaf:holdsAccount ?flickr. ?flickr foaf:accountServiceHomepage <http://flickr.com> }
Login to test this query using our experimental API explorer Permalink to this sample query

For a given organization code, this query will return the URI for the organization, its name and, where available references to its homepage, RSS feed, Facebook page, Flickr and Twitter accounts.

Query: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX nhs: <http://data.kasabi.com/dataset/nhs-organization/def/> PREFIX org: <http://www.w3.org/ns/org#> SELECT ?org ?name ?homepage ?facebook ?flickr ?twitter ?rss WHERE { ?org rdfs:label ?name; org:identifier "5A4"^^nhs:odsCode. OPTIONAL { ?org foaf:homepage ?homepage. } OPTIONAL { ?org foaf:isPrimaryTopicOf ?facebook. FILTER( regex(str(?facebook), "facebook") ) } OPTIONAL { ?org foaf:holdsAccount ?flickr. ?flickr foaf:accountServiceHomepage <http://flickr.com>. } OPTIONAL { ?org foaf:holdsAccount ?twitter. ?twitter foaf:accountServiceHomepage <http://twitter.com>. } OPTIONAL { ?org sioc:feed ?rss. } }
Login to test this query using our experimental API explorer Permalink to this sample query
Create a sample query